{"id":13622424,"url":"https://github.com/importcjj/rust-ajson","last_synced_at":"2025-04-09T09:09:04.142Z","repository":{"id":55990513,"uuid":"198683286","full_name":"importcjj/rust-ajson","owner":"importcjj","description":"Rust port of gjson，get JSON value by dotpath syntax","archived":false,"fork":false,"pushed_at":"2022-08-31T03:51:16.000Z","size":294,"stargazers_count":99,"open_issues_count":2,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-01-01T10:10:30.587Z","etag":null,"topics":["ajson","dotpath","json","json-parser","json-path","json-rs","rust","serde-json"],"latest_commit_sha":null,"homepage":"https://importcjj.github.io/rust-ajson-playground/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/importcjj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-24T17:44:08.000Z","updated_at":"2023-12-10T18:26:17.000Z","dependencies_parsed_at":"2022-08-15T11:00:22.138Z","dependency_job_id":null,"html_url":"https://github.com/importcjj/rust-ajson","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Frust-ajson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Frust-ajson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Frust-ajson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Frust-ajson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/importcjj","download_url":"https://codeload.github.com/importcjj/rust-ajson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ajson","dotpath","json","json-parser","json-path","json-rs","rust","serde-json"],"created_at":"2024-08-01T21:01:18.936Z","updated_at":"2025-04-09T09:09:04.123Z","avatar_url":"https://github.com/importcjj.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries"],"sub_categories":["Encoding","编码 Encoding"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003c!-- \u003cimg alt=\"AJSON\" src=\"logo.png\"\u003e --\u003e\n  \u003ch1\u003eA-JSON\u003c/h1\u003e\n  \u003cp\u003eRead JSON values quickly - Rust JSON Parser\u003c/p\u003e\n\n  \u003ca href=\"https://github.com/importcjj/rust-ajson\"\u003e\n  \u003cimg src=\"https://github.com/importcjj/rust-ajson/actions/workflows/rust.yml/badge.svg\"\u003e\u003c/a\u003e\n\n  \u003ca href=\"https://crates.io/crates/ajson\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/crates.io-0.2.1-blue\"\u003e\u003c/a\u003e\n\n  \u003ca href=\"https://importcjj.github.io/rust-ajson-playground/\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/goto-playground-orange\"\u003e\n\n\u003c/a\u003e\n\n\n\u003c/div\u003e\n\n\n#### change name to AJSON, see [issue](https://github.com/importcjj/a-json/issues/2)\nInspiration comes from [gjson](https://github.com/tidwall/gjson) in golang\n\n## Installation\nAdd it to your `Cargo.toml` file:\n```\n[dependencies]\najson = \"0.3\"\n```\n\n## Todo\n\n* Add documentation\n* Follow api-guidelines\n* Update benchmark\n* Optimize\n\n## A simple example\n\nAJSON get json value with specified path, such as `project.name` or `project.version`. When the path matches, it returns immediately!\n\n```rust\nlet data = r#\"\n{\n  \"project\": {\n    \"name\": \"ajson\",\n    \"maintainer\": \"importcjj\",\n    \"version\": 0.1,\n    \"rusts\": [\"stable\", \"nightly\"]\n  }\n}\n\"#;\n\nlet name = ajson::get(data, \"project.name\").unwrap().unwrap();\nprintln!(\"{}\", name.as_str()); // ajson\n```\n\n## Path Syntax\n\nJSON example\n\n```json\n{\n    \"name\": {\"first\": \"Tom\", \"last\": \"Anderson\"},\n    \"age\":37,\n    \"children\": [\"Sara\",\"Alex\",\"Jack\"],\n    \"fav.movie\": \"Deer Hunter\",\n    \"friends\": [\n        {\"first\": \"Dale\", \"last\": \"Murphy\", \"age\": 44, \"nets\": [\"ig\", \"fb\", \"tw\"]},\n        {\"first\": \"Roger\", \"last\": \"Craig\", \"age\": 68, \"nets\": [\"fb\", \"tw\"]},\n        {\"first\": \"Jane\", \"last\": \"Murphy\", \"age\": 47, \"nets\": [\"ig\", \"tw\"]}\n    ]\n}\n```\n\n#### basic\nBelow is a quick overview of the path syntax, for more complete information please check out GJSON Syntax.\n\nA path is a series of keys separated by a dot. A key may contain special wildcard characters '*' and '?'. To access an array value use the index as the key. To get the number of elements in an array or to access a child path, use the '#' character. The dot and wildcard characters can be escaped with '\\'.\n\n```\nname.last        \u003e\u003e \"Anderson\"\nage              \u003e\u003e 37\nchildren         \u003e\u003e [\"Sara\",\"Alex\",\"Jack\"]\nchildren.#       \u003e\u003e 3\nchildren.1       \u003e\u003e \"Alex\"\nchild*.2         \u003e\u003e \"Jack\"\nc?ildren.0       \u003e\u003e \"Sara\"\nfav\\.movie       \u003e\u003e \"Deer Hunter\"\nfriends.#.first  \u003e\u003e [\"Dale\",\"Roger\",\"Jane\"]\nfriends.1.last   \u003e\u003e \"Craig\"\n```\n\n#### Escape character\nSpecial purpose characters, such as ., *, and ? can be escaped with \\.\n\n```\nfav\\.movie             \"Deer Hunter\"\n```\n\n#### Arrays\nThe # character allows for digging into JSON Arrays.To get the length of an array you'll just use the # all by itself.\n\n```\nfriends.#              3\nfriends.#.age         [44,68,47]\n```\n\n#### queries\nYou can also query an array for the first match by using #(...), or find all matches with #(...)#. Queries support the ==, !=, \u003c, \u003c=, \u003e, \u003e= comparison operators and the simple pattern matching % (like) and !% (not like) operators.\n\n```\nfriends.#(last==\"Murphy\").first   \u003e\u003e \"Dale\"\nfriends.#(last==\"Murphy\")#.first  \u003e\u003e [\"Dale\",\"Jane\"]\nfriends.#(age\u003e45)#.last           \u003e\u003e [\"Craig\",\"Murphy\"]\nfriends.#(first%\"D*\").last        \u003e\u003e \"Murphy\"\nfriends.#(nets.#(==\"fb\"))#.first  \u003e\u003e [\"Dale\",\"Roger\"]\n```\n\n#### construct\nBasically, you can use selectors to assemble whatever you want, and of course, the result is still a json ;)\n\n\n```\n{name.first,age,\"murphys\":friends.#(last=\"Murphy\")#.first}\n[name.first,age,children.0]\n```\n\n```rust\najson::get(json, \"name.[first,last]\").unwrap().unwrap().to_vec();\najson::get(json, \"name.first\").unwrap().unwrap(); \najson::get(json, \"name.last\").unwrap().unwrap();\n```\n\n## Value\n\nValue types.\n```rust\nenum Value {\n    String(String),\n    Number(Number),\n    Object(String),\n    Array(String),\n    Boolean(bool),\n    Null,\n}\n```\n\nValue has a number of methods that meet your different needs.\n\n```rust\nvalue.get(\u0026str) -\u003e Option\u003cValue\u003e\nvalue.as_str() -\u003e \u0026str\nvalue.as_u64() -\u003e u64\nvalue.as_i64() -\u003e i64\nvalue.as_f64() -\u003e f64\nvalue.as_bool() -\u003e bool\nvalue.as_vec() -\u003e Vec\u003cValue\u003e\nvalue.as_object() -\u003e HashMap\u003cString, Value\u003e\n```\n\n\n```rust\nvalue.is_number() -\u003e bool\nvalue.is_string() -\u003e bool\nvalue.is_bool() -\u003e bool\nvalue.is_object() -\u003e bool\nvalue.is_array() -\u003e bool\nvalue.is_null() -\u003e bool\n```\n\n## Performance\n\n`$ cargo bench`\n\n* [ajson](https://github.com/importcjj/ajson)\n* [serde_json](https://github.com/serde-rs/json)\n* [rust-json](https://github.com/maciejhirsz/json-rust)\n\n```\najson benchmark         time:   [2.0816 us 2.0865 us 2.0917 us]                             \n                        change: [+0.6172% +0.9272% +1.2430%] (p = 0.00 \u003c 0.05)\n                        Change within noise threshold.\nFound 11 outliers among 100 measurements (11.00%)\n  7 (7.00%) high mild\n  4 (4.00%) high severe\n\nserde_json benchmark    time:   [23.033 us 23.076 us 23.119 us]                                  \n                        change: [-0.7185% -0.3455% +0.0230%] (p = 0.07 \u003e 0.05)\n                        No change in performance detected.\nFound 7 outliers among 100 measurements (7.00%)\n  6 (6.00%) high mild\n  1 (1.00%) high severe\n\njson-rust benchmark     time:   [12.225 us 12.289 us 12.381 us]                                 \n                        change: [-2.6200% -1.1789% +0.8442%] (p = 0.19 \u003e 0.05)\n                        No change in performance detected.\nFound 9 outliers among 100 measurements (9.00%)\n  5 (5.00%) high mild\n  4 (4.00%) high severe\n\najson selector          time:   [1.1523 us 1.1561 us 1.1604 us]                            \n                        change: [+0.1567% +0.7278% +1.2945%] (p = 0.01 \u003c 0.05)\n                        Change within noise threshold.\nFound 3 outliers among 100 measurements (3.00%)\n  3 (3.00%) high mild\n\najson multi query       time:   [559.19 ns 559.96 ns 560.77 ns]                               \n                        change: [-1.4268% -1.0380% -0.6698%] (p = 0.00 \u003c 0.05)\n                        Change within noise threshold.\nFound 3 outliers among 100 measurements (3.00%)\n  3 (3.00%) high mild\n\nserde derive            time:   [4.5301 us 4.5403 us 4.5507 us]                          \n                        change: [-2.3423% -1.9438% -1.5697%] (p = 0.00 \u003c 0.05)\n                        Performance has improved.\nFound 2 outliers among 100 measurements (2.00%)\n  2 (2.00%) high mild\n\nserde derive multi query                        \n                        time:   [956.86 ns 962.64 ns 970.05 ns]\n                        change: [-1.7069% -1.0299% -0.2924%] (p = 0.01 \u003c 0.05)\n                        Change within noise threshold.\nFound 9 outliers among 100 measurements (9.00%)\n  3 (3.00%) high mild\n  6 (6.00%) high severe\n\nnom json bench          time:   [2.9468 us 2.9515 us 2.9566 us]\nFound 5 outliers among 100 measurements (5.00%)\n  4 (4.00%) high mild\n  1 (1.00%) high severe\n```\n\n* MacBook Pro (14-inch, 2021)\n* Apple M1 Pro\n* 16 GB\n\n## License\n MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimportcjj%2Frust-ajson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimportcjj%2Frust-ajson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimportcjj%2Frust-ajson/lists"}