{"id":13645335,"url":"https://github.com/Fugoes/ctrj","last_synced_at":"2025-04-21T14:30:27.724Z","repository":{"id":119118299,"uuid":"274607720","full_name":"Fugoes/ctrj","owner":"Fugoes","description":"Compile Time RapidJSON: A compile time C++ header only JSON library without bloating yet another hand-crafted JSON parser based on RapidJSON.","archived":false,"fork":false,"pushed_at":"2020-06-29T04:22:12.000Z","size":94,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-02T01:25:19.266Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Fugoes.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-06-24T07:46:48.000Z","updated_at":"2022-10-04T02:45:08.000Z","dependencies_parsed_at":"2023-05-31T02:30:29.721Z","dependency_job_id":null,"html_url":"https://github.com/Fugoes/ctrj","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fugoes%2Fctrj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fugoes%2Fctrj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fugoes%2Fctrj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fugoes%2Fctrj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fugoes","download_url":"https://codeload.github.com/Fugoes/ctrj/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223868049,"owners_count":17217015,"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":[],"created_at":"2024-08-02T01:02:33.663Z","updated_at":"2024-11-09T18:30:55.329Z","avatar_url":"https://github.com/Fugoes.png","language":"C++","readme":"# CTRJ\n\n(C)ompile (T)ime (R)apid(J)SON.\n\nMany people out there have written compile time JSON libraries and bloat their own JSON parsers. This is the compile time JSON library which does not bloat yet another one.\n\n## Overview\n\n- Header only.\n- Provide reader API \u0026 writer API based on RapidJSON's writer API \u0026 SAX reader API.\n- High performance. See benchmark session below.\n- Type safe. Access to JSON object's properties are type-checked at compile time.\n- Allocation free parser. When using the reader API, no allocation happens besides memory needed by the JSON object.\n\n## Usage\n\n### Installation\n\nJust copy the `ctrj/` folder to your project.\n\n### Defining Schema\n\nHere is an example from `test/test_citm_catalogs.cpp`:\n\n```C++\n#include \"ctrj/schema.hpp\"\n\nnamespace {\nconst char _areaNames[] = \"areaNames\";\nconst char _audienceSubCategoryNames[] = \"audienceSubCategoryNames\";\n// other keys ...\n}\n\nusing js_schema = ctrj::obj\u003c\n    ctrj::fld\u003c_areaNames, ctrj::dyn_obj\u003cctrj::str\u003e\u003e,\n    ctrj::fld\u003c_audienceSubCategoryNames, ctrj::dyn_obj\u003cctrj::str\u003e\u003e,\n    ctrj::fld\u003c_blockNames, ctrj::dyn_obj\u003cctrj::str\u003e\u003e,\n    ctrj::fld\u003c_events, ctrj::dyn_obj\u003cctrj::obj\u003c\n        ctrj::fld\u003c_description, ctrj::nul\u003cctrj::str\u003e\u003e,\n        ctrj::fld\u003c_id, ctrj::u64\u003e,\n        ctrj::fld\u003c_subTopicIds, ctrj::arr\u003cctrj::u64\u003e\u003e,\n        ctrj::fld\u003c_subjectCode, ctrj::nul\u003cctrj::u64\u003e\u003e,\n        ctrj::fld\u003c_subtitle, ctrj::nul\u003cctrj::str\u003e\u003e,\n        ctrj::fld\u003c_topicIds, ctrj::arr\u003cctrj::u64\u003e\u003e\n    \u003e\u003e\u003e,\n    ctrj::fld\u003c_venueNames, ctrj::dyn_obj\u003cctrj::str\u003e\u003e\n\u003e;\n```\n\nAll supported schema elements are:\n\n- Primitive types:\n  - `ctrj::u64` for 64-bit unsigned integer,\n  - `ctrj::i64` for 64-bit signed integer,\n  - `ctrj::f64` for double,\n  - `ctrj::str` for string,\n  - `ctrj::bol` for boolean.\n- Compound types (all type parameters could be another compound type):\n  - `ctrj::arr\u003cT\u003e` for array of type `T`,\n  - `ctrj::nul\u003cT\u003e` for nullable type of type `T`,\n  - `ctrj::obj\u003cctrj::fld\u003cK0, T0\u003e, ctrj::fld\u003cK1, T1\u003e, ..., ctrj::fld\u003cKn, Tn\u003e\u003e` for object with `K0` property of type `T0`, `K1` property of type `T1`, ..., `Kn` property of type `Tn`,\n  - `ctrj::dyn_obj\u003cT\u003e` for object with dynamic keys, and all these keys point to value of type `T`.\n\n### Using JSON Objects\n\n`ctrj::val\u003cT\u003e` represents a JSON object of schema `T`. After you create an instance of `ctrj::val\u003cT\u003e`, your IDE would guide you. JSON types are mapped into STL types.\n\nHere is an example for the above schema:\n\n```C++\n#include \"ctrj/value.hpp\"\n\n// schema definition\n\nint main() {\n  ctrj::val\u003cjs_schema\u003e js{};\n\n  js.get\u003c_areaNames\u003e().flds[\"some field\"].str = \"some value\";\n  auto \u0026event = js.get\u003c_events\u003e().flds[\"some event\"];\n  event.get\u003c_description\u003e().opt.emplace(ctrj::val\u003cctrj::str\u003e{});\n  event.get\u003c_subTopicIds\u003e().vec.push_back({});\n  event.get\u003c_subTopicIds\u003e().vec[0].u64 = 0xdeadbeef;\n  // ...\n}\n```\n\n### Reading JSON\n\nHere is an example for the above schema:\n\n```C++\n#include \"ctrj/reader.hpp\"\n\nint main() {\n  // ...\n  using handler_t = ctrj::reader\u003cjs_schema, rapidjson::BaseReaderHandler,\n                                 rapidjson::UTF8\u003c\u003e\u003e;\n  rapidjson::StringStream ss{content_c_str};\n  rapidjson::Reader reader{};\n  handler_t handler{js};\n  reader.Parse(ss, handler);\n  if (reader.HasParseError()) std::cout \u003c\u003c \"ERROR\" \u003c\u003c std::endl;\n  // ...\n}\n```\n\n### Writing JSON\n\nHere is an example for the above schema:\n\n```C++\n#include \"ctrj/writer.hpp\"\n\nint main() {\n  // ...\n  rapidjson::StringBuffer buf{};\n  rapidjson::Writer w{buf};\n  ctrj::write\u003cjs_schema\u003e(js).to(w);\n  std::cout \u003c\u003c buf.GetString() \u003c\u003c std::endl;\n  // ...\n}\n```\n\n## Benchmark\n\nFirstly, build this repo using `cmake`. Use `Release` build type please. To run some benchmark:\n\n```bash\n# benchmarking RapidJSON's Document::Parse\n./test_bench_rj 1000 path/to/ctrj/data/citm_catalog.json\n# benchmarking CTRJ's parse \u0026 validate\n./test_citm_catalogs 1000 path/to/ctrj/data/citm_catalog.json\n```\n\nUsually `CTRJ` achieves about 70%~80% of the throughput of RapidJSON. Please note that, RapidJSON's benchmark does NOT include validation of schema.","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFugoes%2Fctrj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFugoes%2Fctrj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFugoes%2Fctrj/lists"}