{"id":27057873,"url":"https://github.com/mrange/cppjson","last_synced_at":"2025-09-14T23:09:10.132Z","repository":{"id":35896080,"uuid":"40182649","full_name":"mrange/cppjson","owner":"mrange","description":"cppjson is a conforming JSON parser for C++11","archived":false,"fork":false,"pushed_at":"2015-08-26T20:57:01.000Z","size":708,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-12T22:01:03.250Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrange.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-04T12:12:50.000Z","updated_at":"2015-08-26T20:59:35.000Z","dependencies_parsed_at":"2022-08-19T03:41:43.967Z","dependency_job_id":null,"html_url":"https://github.com/mrange/cppjson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mrange/cppjson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Fcppjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Fcppjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Fcppjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Fcppjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrange","download_url":"https://codeload.github.com/mrange/cppjson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrange%2Fcppjson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275180222,"owners_count":25419066,"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-14T02:00:10.474Z","response_time":75,"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":"2025-04-05T11:33:49.540Z","updated_at":"2025-09-14T23:09:10.109Z","avatar_url":"https://github.com/mrange.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cppjson\n\ncppjson is a [conforming](http://jsonlint.com) [JSON](http://json.org) parser for C++ licensed under\n[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nLike [minijson_reader](https://github.com/giacomodrago/minijson_reader) cppjson wants to allow\ndevelopers parse JSON documents without the overhead of DOM.\n\nFor developers that don't mind DOM like parsing of JSON document a simple DOM is provided.\n\ncppjson is based on my work on [MiniJson](https://github.com/mrange/minijson) for F#\n(not to be confused with minijson_reader, I discovered minijson_reader after creating MiniJson for F#)\ncppjson uses MiniJson as a reference parser (MiniJson has a rather extensive test suite).\n\nLike MiniJson for F# cppjson wants to provide decent error messages, example:\n```\nFailed to parse input as JSON\n{\"abc\":}\n-------^ Pos: 7\nExpected: '\"', '-', '[', '{', digit, false, null or true\n```\n\ncppjson dom parsing\n```cpp\n#include \"cpp_json__document.hpp\"\n\nvoid parse_json (std::wstring const \u0026 json)\n{\n  using namespace cpp_json::document;\n\n  std::size_t         pos     ;\n  json_document::ptr  document;\n  std::wstring        error   ;\n\n  if (!json_parser::parse (json, pos, document))\n  {\n    std::wcout\n      \u003c\u003c L\"FAILURE: Pos: \" \u003c\u003c pos \u003c\u003c std::endl\n      \u003c\u003c error \u003c\u003c std::endl\n      ;\n  }\n  else\n  {\n    auto root = document-\u003eroot ();\n    auto sz = root-\u003esize ();\n    for (auto iter = 0U; iter \u003c sz; ++iter)\n    {\n      std::wcout \u003c\u003c root-\u003eat (iter)-\u003eas_string () \u003c\u003c std::endl;\n    }\n  }\n}\n```\n\ncppjson callback parsing\n```cpp\n#include \"cpp_json__parser.hpp\"\n\nstruct some_json_context\n{\n  using string_type = std::wstring    ; // Type of string, typically std::wstring\n  using char_type   = wchar_t         ; // Type of char, typically wchar_t\n  using iter_type   = wchar_t const * ; // Type of string \"iterator\", typically wchar_t const *\n\n  // expected* methods are invoked when parser expected a token but didn't find it\n  //  Note: certain elements are considered optional so a call to an expected* method might not stop parsing\n  void expected_char    (std::size_t pos, char_type ch) noexcept\n  void expected_chars   (std::size_t pos, string_type const \u0026 chs) noexcept\n  void expected_token   (std::size_t pos, string_type const \u0026 token) noexcept\n\n  // unexpected* methods are invoked when parser encountered an unexpected token\n  //  Note: certain elements are considered optional so a call to an unexpected* method might not stop parsing\n  void unexpected_token (std::size_t pos, string_type const \u0026 token);\n\n  // Methods used to build string values\n\n  // Clears cached string\n  void clear_string ();\n  // Appends an 8-bit or 16-bit char to string (depending on char_type)\n  void push_char (char_type ch);\n  // Appends an 16-bit char to string (allows encoding when char_type is char)\n  void push_wchar_t (wchar_t ch);\n  // Gets cached string\n  string_type const \u0026 get_string ();\n\n  // The following methods are invoked when JSON values are discovered\n\n  bool array_begin ();\n  bool array_end ();\n\n  bool object_begin ();\n  bool member_key (string_type const \u0026 s);\n  bool object_end ();\n\n  bool bool_value (bool b);\n\n  bool null_value ();\n\n  bool string_value (string_type const \u0026 s);\n\n  bool number_value (double d);\n};\n\n\nvoid parse_json (std::wstring const \u0026 json)\n{\n  using namespace cpp_json::parser;\n\n  auto b = json.c_str ()    ;\n  auto e = b + json.size () ;\n  json_parser\u003csome_json_context\u003e jp (b, e);\n\n  auto result = jp.try_parse__json ();\n  if (!result)\n  {\n    // Handle error\n    // ...\n  }\n\n  // Parse successful\n  // ...\n}\n```\n\n# TODO\n\n1. Improve error message test coverage\n1. Add test cases for memory allocation\n1. Add mutability to json_document\n1. Remove C++11 dependency\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrange%2Fcppjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrange%2Fcppjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrange%2Fcppjson/lists"}