{"id":13742480,"url":"https://github.com/xlc/lite-json","last_synced_at":"2025-04-06T01:08:32.136Z","repository":{"id":52934009,"uuid":"222383143","full_name":"xlc/lite-json","owner":"xlc","description":"Simple JSON parser written with Rust. Wasm / no_std ready.","archived":false,"fork":false,"pushed_at":"2022-07-05T23:38:09.000Z","size":34,"stargazers_count":50,"open_issues_count":6,"forks_count":24,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T00:07:07.141Z","etag":null,"topics":["json-parser","no-std","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/xlc.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-11-18T06:58:18.000Z","updated_at":"2024-11-20T14:01:26.000Z","dependencies_parsed_at":"2022-08-24T13:50:42.088Z","dependency_job_id":null,"html_url":"https://github.com/xlc/lite-json","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlc%2Flite-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlc%2Flite-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlc%2Flite-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlc%2Flite-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xlc","download_url":"https://codeload.github.com/xlc/lite-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419860,"owners_count":20936012,"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":["json-parser","no-std","rust"],"created_at":"2024-08-03T05:00:32.754Z","updated_at":"2025-04-06T01:08:32.111Z","avatar_url":"https://github.com/xlc.png","language":"Rust","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# lite-json\n\n[![Crates.io](https://img.shields.io/crates/v/lite-json)](https://crates.io/crates/lite-json)\n[![GitHub](https://img.shields.io/github/license/xlc/lite-json)](https://github.com/xlc/lite-json/blob/master/LICENSE)\n\nSimple JSON parser written with Rust. Wasm / no_std ready.\n\n## How to Add in Cargo.toml\n\n### std\n```toml\n[dependencies]\nlite-json = \"0.2.0\"\n```\n\n### no_std\n```toml\n[dependencies]\nlite-json = { version = \"0.2.0\", default-features = false, defaults = [\"no_std\"] }\n```\n\n## Example Usage\n\n### Creating JSON\n\nThis example will create a lite-json structure, then print it as a JSON string.\n\n```rs\nuse lite_json::Serialize;\nuse lite_json::json::{JsonValue, NumberValue};\n\nfn main()\n{\n\t// We will create a bunch of elements that we will put into a JSON Object.\n\tlet mut object_elements = vec!();\n\n\t// Create a boolean value and add it to our vector.\n\tlet boolean_value = true;\n\tlet object_key = \"boolean\".chars().collect();\n\tobject_elements.push((object_key, JsonValue::Boolean(boolean_value)));\n\n\t// Create an array value and add it to our vector.\n\tlet array_value = vec!(JsonValue::Boolean(true), JsonValue::Boolean(false), JsonValue::Boolean(true));\n\tlet object_key = \"array\".chars().collect();\n\tobject_elements.push((object_key, JsonValue::Array(array_value)));\n\n\t// Create a string value and add it to our vector.\n\tlet string_value = \"Hello World!\".chars().collect();\n\tlet object_key = \"string\".chars().collect();\n\tobject_elements.push((object_key, JsonValue::String(string_value)));\n\n\t// Create a number value and add it to our vector.\n\tlet number_value = NumberValue\n\t{\n\t\tinteger: 1234,\n\t\tfraction: 0,\n\t\tfraction_length: 0,\n\t\texponent: 0,\n\t};\n\tlet object_key = \"number\".chars().collect();\n\tobject_elements.push((object_key, JsonValue::Number(number_value)));\n\n\t// Create a null value and add it to our vector.\n\tlet object_key = \"null\".chars().collect();\n\tobject_elements.push((object_key, JsonValue::Null));\n\n\t// Create the object value from the vector of elements.\n\tlet object_value = JsonValue::Object(object_elements);\n\n\t// Convert the object to a JSON string.\n\tlet json = object_value.format(4);\n\tlet json_output = std::str::from_utf8(\u0026json).unwrap();\n\n\tprintln!(\"{}\", json_output);\n}\n```\n\nThis will output:\n```json\n{\n    \"boolean\": true,\n    \"array\": [\n        true,\n        false,\n        true\n    ],\n    \"string\": \"Hello World!\",\n    \"number\": 1234,\n    \"null\": null\n}\n```\n\n### Parsing JSON\n\nThis example will parse a JSON string into a lite-json structure.\n\n```rs\nuse lite_json::json_parser::parse_json;\n\nfn main()\n{\n\t// This is the JSON string we will use.\n\tlet json_string =\n\tr#\"\n\t\t{\n\t\t\t\"boolean\": true,\n\t\t\t\"array\":\n\t\t\t[\n\t\t\t\ttrue,\n\t\t\t\tfalse,\n\t\t\t\ttrue\n\t\t\t],\n\t\t\t\"string\": \"Hello World!\",\n\t\t\t\"number\": 1234,\n\t\t\t\"null\": null\n\t\t}\n\t\"#;\n\n\t// Parse the JSON and print the resulting lite-json structure.\n\tlet json_data = parse_json(json_string).expect(\"Invalid JSON specified!\");\n\tprintln!(\"{:?}\", json_data);\n}\n```\n\n### Parsing JSON with Options\n\nThe parser options allows you to set the max depth of parsing nested objects. This code will result in an error because the max nest level is set to `1`, but the depth of our JSON is `2` due to the presence of a nested array.\n\nNote: This example requires the `lite-parser` crate to be added to `Cargo.toml`.\n\n```rs\nuse lite_json::json_parser::parse_json_with_options;\nuse lite_parser::parser::ParserOptions;\n\nfn main()\n{\n\t// This is the JSON string we will use.\n\tlet json_string =\n\tr#\"\n\t\t{\n\t\t\t\"boolean\": true,\n\t\t\t\"array\":\n\t\t\t[\n\t\t\t\ttrue,\n\t\t\t\tfalse,\n\t\t\t\ttrue\n\t\t\t],\n\t\t\t\"string\": \"Hello World!\",\n\t\t\t\"number\": 1234,\n\t\t\t\"null\": null\n\t\t}\n\t\"#;\n\n\tlet parser_options = ParserOptions\n\t{\n\t\tmax_nest_level: Some(1)\n\t};\n\n\t// Parse the JSON and print the resulting lite-json structure.\n\tlet json_data = parse_json_with_options(json_string, parser_options).expect(\"Invalid JSON specified!\");\n\tprintln!(\"{:?}\", json_data);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlc%2Flite-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxlc%2Flite-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlc%2Flite-json/lists"}