{"id":20373128,"url":"https://github.com/st235/jsonc","last_synced_at":"2026-06-07T00:31:58.938Z","repository":{"id":245564584,"uuid":"818457054","full_name":"st235/JSONC","owner":"st235","description":"JSONC is a lightweight implementation of JSON Data Interchange Standard for C++ programming language.","archived":false,"fork":false,"pushed_at":"2024-07-26T22:03:59.000Z","size":231,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T20:43:53.221Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","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/st235.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-21T22:49:52.000Z","updated_at":"2025-01-23T13:40:57.000Z","dependencies_parsed_at":"2025-01-15T05:44:14.652Z","dependency_job_id":"1af08151-d08f-4ea1-94a4-ed8f1663d3a6","html_url":"https://github.com/st235/JSONC","commit_stats":null,"previous_names":["st235/jsonc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/st235/JSONC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FJSONC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FJSONC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FJSONC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FJSONC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/st235","download_url":"https://codeload.github.com/st235/JSONC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FJSONC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34005030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-06T02:00:07.033Z","response_time":107,"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-11-15T01:16:44.410Z","updated_at":"2026-06-07T00:31:58.922Z","avatar_url":"https://github.com/st235.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSONC\n\n`JSONC` is a lightweight implementation of `JSON` Data Interchange Standard for `C++` programming language.\n\nIt is an ideal candidate to use with microcontrollers. The library was tested with [`Raspberry Pi Pico and Pico W`](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html).\n\n`JSON` + `C++` = ❤️\n\n## Add dependency\n\n### CMake\n\n`CMake` provides a convenient way to depend on the library.\n\n```cmake\ninclude(FetchContent)\n\nFetchContent_Declare(\n  JSONC\n  GIT_REPOSITORY git@github.com:st235/JSONC.git\n  GIT_TAG \"main\"\n  GIT_SHALLOW TRUE\n  GIT_PROGRESS ON\n)\nFetchContent_MakeAvailable(JSONC)\n\ntarget_link_libraries(your-project-target jsonc)\n```\n\nCheck out [`samples`](./samples/) for more.\n\n## Exploring the API\n\nAlmost everything you might expect has been implemented. Take a look at this real-life example:\n\n```cpp\n  if (response.isObject() \u0026\u0026 response[\"results\"].isArray()) {\n      const auto\u0026 results_array = response[\"results\"].asArray();\n\n      for (size_t i = 0; i \u003c results_array.size(); i++) {\n          const auto\u0026 raw_character = results_array[i];\n\n          Character c = {\n              uint32_t(raw_character[\"id\"].asNumber()),\n              raw_character[\"name\"].asString(),\n              raw_character[\"species\"].asString(),\n              raw_character[\"gender\"].asString(),\n              raw_character[\"image\"].asString()\n          };\n\n          ...\n      }\n  }\n```\n\nHere are a few more examples of the most common use cases for your reference.\n\n### Create `Json` object from a `string`\n\n```cpp\nstd::string json_text = ...\nconst auto\u0026 json = json::Json::fromJson(json_text);\n```\n\n### Declare `Json` object and dump it to back to `string`\n\n```cpp\njson::Json json = { \n  std::make_pair(\"a\", json::Json({ json::Json(true), json::Json(\"b\") })),\n  std::make_pair(\"b\", json::Json(129.1))\n};\n\nstd::string json_text = json::Json::toString(json);\n```\n\nIn this example, the `json object` will be _minified_. If you want to _beautify_ the JSON (i.e., make it human-readable), the library offers a default implementation of `JsonBeautifier`, which you can find in [the samples folder.](./samples/)\n\n### Types\n\nThe following paragraphs provide a deep dive into the implementation details of the library.\n\nJSON specification declares 4 types and 3 literals:\n- Literals\n    - `null`\n    - `true`\n    - `false`\n- Types\n    - `number`\n    - `string`\n    - `array`\n    - `object`\n\nAll json values are conform to specially defined [`json::Json` type](./include/json.h).\nTo check for those literals and types `Json` defines special **boolean methods**:\n\n- `Json#isNull`\n- `Json#isBool`\n- `Json#isNumber`\n- `Json#isString`\n- `Json#isArray`\n- `Json#isObject`\n\nAlmost all `is` methods (except `isNull`) has corresponding `as` methods to safely get the content of json file:\n\n- `asBool` -\u003e returns `bool`\n- `asNumber` -\u003e `double`\n- `asString` -\u003e `std::string`\n- `asArray` -\u003e `std::vector\u003cJson\u003e`\n- `asObject` -\u003e `std::unordered_map\u003cstd::string, Json\u003e`\n\n## Json Grammar Rules\n\nThe specification of JSON format is available at [_the oficial website_](https://www.json.org/json-en.html) or as [_ECMA-404 The JSON Data Interchange Standard_](https://ecma-international.org/publications-and-standards/standards/ecma-404/).\n\nThe grammar specifies 6 entries: `array`, `number`, `object`, `string`, `value`, and `whitespace`.\n`value` is the entry point.\n\nI won't cover all the details of the implemention but will provide the most important grammar rules.\n\n| Array | Number | Object |\n| ----- | ----- | ----- |\n| ![Array](./images/array.png) | ![Number](./images/number.png) | ![Object](./images/object.png) |\n\n| String | Value | Whitespace |\n| ----- | ----- | ----- |\n| ![String](./images/string.png) | ![Value](./images/value.png) | ![Whitespace](./images/whitespace.png) |\n\n## Contribution\n\nThe project is using `CMake` as the build system.\n\n### Building\n\nUse these commands to build the project:\n\n```bash\nmkdir build\ncmake .. -DCOMPILE_TESTS=ON -DASSERT=ON\nmake\n```\n\n`ASSERT=ON` is used to enabled assertions in the codebase. If you're building a release flavour then you may consider to do not specify this setting.\n\n### Running test\n\nA lot of logic in the library heavily relies on _unit_ and _integration_ tests.\nTo run them you need yo _successfully build the project_ and run the command below:\n\n```bash\nctest --output-on-failure\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst235%2Fjsonc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fst235%2Fjsonc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst235%2Fjsonc/lists"}