{"id":14842661,"url":"https://github.com/noir-lang/noir_json_parser","last_synced_at":"2025-09-18T02:32:39.496Z","repository":{"id":253936112,"uuid":"844744547","full_name":"noir-lang/noir_json_parser","owner":"noir-lang","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-01T10:05:07.000Z","size":18206,"stargazers_count":15,"open_issues_count":11,"forks_count":4,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-01T12:32:44.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Noir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noir-lang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-19T22:16:46.000Z","updated_at":"2025-09-01T09:57:11.000Z","dependencies_parsed_at":"2024-10-24T17:26:53.139Z","dependency_job_id":"f479b672-6526-4bdf-a348-83a8ef2c727c","html_url":"https://github.com/noir-lang/noir_json_parser","commit_stats":null,"previous_names":["noir-lang/noir_json_parser"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/noir-lang/noir_json_parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_json_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_json_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_json_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_json_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noir-lang","download_url":"https://codeload.github.com/noir-lang/noir_json_parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noir-lang%2Fnoir_json_parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275697248,"owners_count":25511584,"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","status":"online","status_checked_at":"2025-09-18T02:00:09.552Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-09-19T12:00:52.501Z","updated_at":"2025-09-18T02:32:39.483Z","avatar_url":"https://github.com/noir-lang.png","language":"Noir","funding_links":[],"categories":["Libraries","Get Coding"],"sub_categories":["Data Type Manipulation","Libraries"],"readme":"# noir_json_parse\n\nA JSON parsing library for the Noir Language. This library adheres to the IETF RFC 8259 specifications (mostly, see [edge_cases](#edge_cases)).\n\nFeatures:\n\n- handles _arbitrary-length_ JSON strings (up to a defined maximum bound)\n- flexible interface can process arbitrary JSON schemas\n- O(1) algorithms to query whether keys exist\n\n## Noir version compatibility\n\nThis library is tested with all Noir stable releases from v0.37.0.\n\n# Usage and Interface\n\nMultiple JSON parser types are exposed that accomodate different maximum length parameters:\n\n\u003e Notation explainer: a _token_ is a distinct JSON element, either `{` `}` `[` `]` `,` `:` , strings, numbers of literals (`false`, `true`, `null`)\n\u003e Notation explainer: a _value_ is an object, array, string, number of literal\n\n- `JSON512b` a parser that can handle up to 512 bytes of JSON, up to 64 _tokens_ and 32 _values_\n- `JSON1kb` a parser that can handle up to 1kb of JSON, up to 128 _tokens_ and 64 _values_\n- `JSON2kb` a parser that can handle up to 2kb bytes of JSON, up to 256 _tokens_ and 128 _values_\n- `JSON4kb` a parser that can handle up to 4kb bytes of JSON, up to 512 _tokens_ and 256 _values_\n- `JSON8kb` a parser that can handle up to 8kb bytes of JSON, up to 1,024 _tokens_ and 512 _values_\n- `JSON16kb` a parser that can handle up to 16kb bytes of JSON, up to 2,048 _tokens_ and 1,024 _values_\n\nThe maximum length of keys in the JSON blob is _62 bytes_. All of these parameters are configurable, see [Advanced usage](#advanced-usage) for more info.\n\n## Usage\n\n```\nuse crate::json_parser::JSON1kb;\nuse crate::json_parser::JSONLiteral;\n/*\nexample schema. In this example we require every field to exist except \"dlc_enabled\", which is optional.\nWe also demonstrate escaped strings. To escape a string in JSON, we must escape the escape characters in noir!\n{\n    \"hero\": \"Tony Harrison\",\n    \"is_player\": false,\n    \"stats\": [\n        {\n            \"hero_quote\": \"\\\\\\\"This is an outrage!\\\\\\\"\",\n            \"power_level\": 1\n        },\n        {\n            \"hero_quote\": \"\\\"The Crunch? You know nothing of the crunch!\\\"\",\n            \"power_level\": 9001\n        }\n    ],\n    \"dlc_enabled\": true\n}\n*/\nfn process_schema(text: [u8; NUM_BYTES])\n{\n    let json: JSON = JSON::parse_json(text);\n\n    // we use the \"unchecked\" method because we want to assert this field exists\n    let hero_name: BoundedVec\u003cu8, 20\u003e = json.get_string_unchecked(\"hero\".as_array());\n    assert(hero_name == BoundedVec::from_array(\"Tony Harrison\".to_array()));\n\n    // json literals can be \"null\", which doesn't map perfectly to a bool, so we use a custom type\n    let is_player: JSONLiteral = json.get_literal_unchecked(\"is_player\".as_array());\n    let is_player = is_player.to_bool(); // can cast to bool if you don't mind null mapping to false\n\n    // to move into a nested object or array, call `get_object` or `get_array`\n    let stats_array: JSON = json.get_array_unchecked(\"stats\".as_array());\n    let stats: [JSON; 2] = [stats.get_object_as_array_unchecked(0), stats.get_object_as_array_unchecked(1)];\n\n    let hero_quote: BoundedVec\u003cu8, 30\u003e = stats[0].get_string_unchecked(\"hero_quote\".as_array());\n    assert(hero_quote == BoundedVec::from_array(\"\\\"This is an outrage!\\\"\".as_array()));\n\n    let power_levels: [u64; 2] = [\n        stats[0].get_number_unchecked(\"power_level\"),\n        stats[1].get_number_unchecked(\"power_level\"),\n    ];\n    assert(power_levels[1] \u003e power_levels[0]);\n\n    // All getter methods have a basic version that returns the element as an Option,\n    // to support cases where a field may or may not exist\n    let dlc_enabled: Option\u003cJSONLiteral\u003e = json.get_literal(\"dlc_enabled\");\n\n    let has_dlc_field = dlc_enabled.is_some();\n}\n```\n\n# Edge Cases\n\n### single value JSON\n\n1. A single value is a valid JSON schema but is not currently supported.\n\ni.e. `let json: JSON = JSON::parse_json(\"9999\")` will fail\n\n### no support for floating point or scientific notation numbers\n\nNumbers must currently fit within a u64 for `get_number` and associated methods to work.\nIn addition, numbers with decimal points currently are not supported, as well as numbers that use scientific notation (e.g. a json blob with `3e5` will create a failing proof)\n\nFor numbers larger than 64 bits, the method `get_value` will work, which will return the ascii raw bytes of the value.\n\n# Advanced Usage\n\n### Fine-grained maximum parameter control\n\nIf the predefined JSON types are not sufficient for your use case, you can define a JSON object with a custom parameterization:\n\nThe JSON struct in `dep::json_parser::json::JSON` is parameterized with the following parameters:\n\n`struct JSON\u003clet NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let MaxNumValues: u32, let MaxKeyFields: u32\u003e`\n\n- `NumBytes` : the maximum size of the initial json blob\n- `NumPackedFields` : take `NumBytes / 31`, round up to the nearest integer, then add 3!\n- `MaxNumTokens`: the maximum number of tokens in the json blob\n- `MaxNumValues`: the maximum number of values in the json blob _plus one_\n- `MaxKeyFields`: the largest size a key can take (in bytes) equals `MaxKeyFields * 31`\n\ne.g. to take the existing 1kb JSON parameters, but also support 124-byte keys, use `JSON\u003c1024, 37, 128, 65, 4\u003e`\n\n### Making queries with keys of unknown length\n\nIf you are deriving a key to look up in-circuit and you do not know the maximum length of the key, all query methods accept the key as a `BoundedVec`\n\n# Acknowledgements\n\nMany thanks to the authors of the OG noir json library https://github.com/RontoSOFT/noir-json-parser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoir-lang%2Fnoir_json_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoir-lang%2Fnoir_json_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoir-lang%2Fnoir_json_parser/lists"}