{"id":26121658,"url":"https://github.com/hominsu/neujson","last_synced_at":"2025-04-13T12:51:24.901Z","repository":{"id":37360643,"uuid":"466728826","full_name":"hominsu/neujson","owner":"hominsu","description":"JSON parser/generator in C++17","archived":false,"fork":false,"pushed_at":"2024-05-22T09:49:36.000Z","size":323,"stargazers_count":46,"open_issues_count":1,"forks_count":10,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-05-22T10:57:47.877Z","etag":null,"topics":["cpp","cpp17","deserialization","generator","json","json-parser","parser","serialization"],"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/hominsu.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},"funding":{"github":"hominsu","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-03-06T12:21:01.000Z","updated_at":"2024-05-28T18:46:10.191Z","dependencies_parsed_at":"2024-05-28T18:46:09.065Z","dependency_job_id":"64c00f90-82c2-41e6-9c4f-21570746ac87","html_url":"https://github.com/hominsu/neujson","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hominsu%2Fneujson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hominsu%2Fneujson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hominsu%2Fneujson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hominsu%2Fneujson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hominsu","download_url":"https://codeload.github.com/hominsu/neujson/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717251,"owners_count":21150388,"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":["cpp","cpp17","deserialization","generator","json","json-parser","parser","serialization"],"created_at":"2025-03-10T14:24:29.086Z","updated_at":"2025-04-13T12:51:24.663Z","avatar_url":"https://github.com/hominsu.png","language":"C++","funding_links":["https://github.com/sponsors/hominsu"],"categories":[],"sub_categories":[],"readme":"\u003cdiv id=\"top\"\u003e\u003c/div\u003e\n\n\u003c!-- PROJECT SHIELDS --\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/hominsu/neujson/graphs/contributors\"\u003e\u003cimg src=\"https://img.shields.io/github/contributors/hominsu/neujson.svg?style=for-the-badge\" alt=\"Contributors\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/hominsu/neujson/network/members\"\u003e\u003cimg src=\"https://img.shields.io/github/forks/hominsu/neujson.svg?style=for-the-badge\" alt=\"Forks\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/hominsu/neujson/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/hominsu/neujson.svg?style=for-the-badge\" alt=\"Stargazers\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/hominsu/neujson/issues\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/hominsu/neujson.svg?style=for-the-badge\" alt=\"Issues\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/hominsu/neujson/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/hominsu/neujson.svg?style=for-the-badge\" alt=\"License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/hominsu/neujson/actions/workflows/docker-publish.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/hominsu/neujson/docker-publish.yml?branch=main\u0026style=for-the-badge\" alt=\"Deploy\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr/\u003e\n\u003cdiv align=\"center\"\u003e\n\u003c!--   \u003ca href=\"https://github.com/hominsu/neujson\"\u003e\n    \u003cimg src=\"images/logo.png\" alt=\"Logo\" width=\"80\" height=\"80\"\u003e\n  \u003c/a\u003e --\u003e\n\n\u003ch3 align=\"center\"\u003eneujson\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    A header-only JSON parser/generator in C++20. It supports both SAX and DOM style API.\n    \u003cbr/\u003e\n    \u003ca href=\"https://me.hauhau.cn/projects/neujson/\"\u003e\u003cstrong\u003eExplore the docs »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr/\u003e\n    \u003cbr/\u003e\n    \u003ca href=\"https://github.com/hominsu/neujson\"\u003eView Demo\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/hominsu/neujson/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/hominsu/neujson/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n##### Translate to: [简体中文](README_zh.md)\n\n## Features\n\n- **Simple, Fast**. neujson contains only header files, does not rely on Boost, and takes full advantage of the template's features. You can \"assemble\" neujson's Handler at will.\n- **API simplicity**. neujson supports both DOM and SAX-style API, where SAX allows custom handlers for streaming processing.\n- **Unicode friendly**. neujson fully supports UTF-8 codec and can parse utF-8 characters such as '\\u0000'.\n- **Multiple input/output streams**. neujson has built-in string input/output streams and file input/output streams, and make full use of memory buffers to improve read and write speed.\n- **STD Streams Wrapper**. neujson provides official wrappers for std::istream and std::ostream, can be combined with neujson's built-in input/output streams.\n- **Performant**. neujson internally implements standards such as IEEE754 and uses high-performance algorithms built into different compilers. neujson also plans to implement Grisu2 algorithm and use SIMD instructions to speed up conversion between floating point numbers and strings.\n\n## Examples\n\n### Usage at a glance\n\nThis simple example parses a JSON string into a document (DOM), make a simple modification of the DOM, and finally stringify the DOM to a JSON string.\n\n```c++\n#include \u003ccstdio\u003e\n\n#include \"neujson/document.h\"\n#include \"neujson/string_write_stream.h\"\n#include \"neujson/writer.h\"\n#include \"sample.h\"\n\nint main() {\n  // 1. Parse a JSON string into DOM.\n  neujson::Document doc;\n  if (const auto err = doc.Parse(kSample[0]); err != neujson::error::OK) {\n    puts(neujson::ParseErrorStr(err));\n    return EXIT_FAILURE;\n  }\n\n  // 2. Modify it by DOM.\n  auto \u0026s = doc[0][\"Longitude\"];\n  s.SetDouble(s.GetDouble() + 100.0);\n\n  // 3. Stringify the DOM\n  neujson::StringWriteStream os;\n  neujson::Writer writer(os);\n  doc.WriteTo(writer);\n\n  // Output\n  fprintf(stdout, \"%.*s\", static_cast\u003cint\u003e(os.get().length()), os.get().data());\n  return 0;\n}\n```\n\nOutput:\n\n```json\n[{\"precision\":\"zip\",\"Latitude\":37.766800000000003,\"Longitude\":-22.395899999999997,\"Address\":\"\",\"City\":\"SAN FRANCISCO\",\"State\":\"CA\",\"Zip\":\"94107\",\"Country\":\"US\"},{\"precision\":\"zip\",\"Latitude\":37.371991000000001,\"Longitude\":-122.02602,\"Address\":\"\",\"City\":\"SUNNYVALE\",\"State\":\"CA\",\"Zip\":\"94085\",\"Country\":\"US\"}]\n```\n\n## Building\n\n### clone the neujson repo\n\n```bash\ngit clone https://github.com/hominsu/neujson.git\n```\n\n## Building\n\nThis project requires C++17. This library uses following projects：\n\nWhen building tests:\n\n- [google/googletest](https://github.com/google/googletest)\n\nWhen building examples:\n\n- [neujson](https://github.com/hominsu/neujson)\n\nAll dependencies are automatically retrieved from github during building, and you do not need to configure them.\n\nWith th CMake build types, you can control whether examples and tests are built.\n\n```bash\ncmake -H. -Bbuild \\\n\t-DCMAKE_BUILD_TYPE=Release \\\n\t-DCMAKE_INSTALL_PREFIX=/Users/hominsu/utils/install \\\n\t-DNEUJSON_BUILD_EXAMPLES=ON \\\n\t-DNEUJSON_BUILD_TESTS=ON\ncmake --build ./build --parallel $(nproc)\nctest -VV --test-dir ./build/ --output-on-failure\ncmake --install ./build\n```\n\nOr just installed as a CMake package.\n\n```bash\ncmake -H. -Bbuild \\\n\t-DNEUJSON_BUILD_EXAMPLES=OFF \\\n\t-DNEUJSON_BUILD_TESTS=OFF\ncmake --install ./build\n```\n\nUinstall\n\n```bash\ncd build\nmake uninstall\n```\n\n## Integration\n\nLocated with `find_package` in CMake.\n\n```cmake\nfind_package(neujson REQUIRED)\ntarget_include_directories(foo PUBLIC ${neujson_INCLUDE_DIRS})\n```\n\n## Benchmark\n\nTo build with benchmark，use `git submodule` to fetch all the data from that third party project and check out the appropriate commit first, then add the benchmark CMake option:\n\n```bash\ngit submodule update --init --recursive\npushd cmake/build\ncmake -DNEUJSON_BUILD_BENCHMARK=ON ../..\n...\n```\n\nThe benchmark is base on the google benchmark\n\n### JSON data\n\n|                          JSON file                           |  Size  |                         Description                          |\n| :----------------------------------------------------------: | :----: | :----------------------------------------------------------: |\n| `canada.json`[source](https://github.com/mloskot/json_benchmark/blob/master/data/canada.json) | 2199KB | Contour of Canada border in [GeoJSON](http://geojson.org/) format. Contains a lot of real numbers. |\n| `citm_catalog.json`[source](https://github.com/RichardHightower/json-parsers-benchmark/blob/master/data/citm_catalog.json) | 1737KB | A big benchmark file with indentation used in several Java JSON parser benchmarks. |\n\n### Sample Results\n\nThe followings are some snapshots from the results of MacBook Air (M1, 2020) with Apple clang 13.1.6\n\n```bash\nRun on (8 X 24.1212 MHz CPU s)\nCPU Caches:\n  L1 Data 64 KiB (x8)\n  L1 Instruction 128 KiB (x8)\n  L2 Unified 4096 KiB (x2)\nLoad Average: 2.04, 1.78, 1.74\n--------------------------------------------------------------------------------------------------------\nBenchmark                                                              Time             CPU   Iterations\n--------------------------------------------------------------------------------------------------------\nBM_neujson_read_parse/citm_catalog.json                             7.04 ms         7.04 ms           72\nBM_nlohmann_read_parse/citm_catalog.json                            10.6 ms         10.6 ms           66\nBM_rapidjson_read_parse/citm_catalog.json                           2.96 ms         2.96 ms          236\nBM_neujson_read_parse_write_file/citm_catalog.json                  7.92 ms         7.92 ms           88\nBM_nlohmann_read_parse_write_file/citm_catalog.json                 12.5 ms         12.5 ms           56\nBM_rapidjson_read_parse_write_file/citm_catalog.json                4.10 ms         4.10 ms          170\nBM_neujson_read_parse_write_string/citm_catalog.json                8.03 ms         8.03 ms           87\nBM_nlohmann_read_parse_write_string/citm_catalog.json               12.7 ms         12.7 ms           55\nBM_rapidjson_read_parse_write_string/citm_catalog.json              3.90 ms         3.90 ms          180\nBM_neujson_read_parse_pretty_write_file/citm_catalog.json           8.84 ms         8.84 ms           79\nBM_nlohmann_read_parse_pretty_write_file/citm_catalog.json          13.3 ms         13.3 ms           53\nBM_rapidjson_read_parse_pretty_write_file/citm_catalog.json         4.56 ms         4.55 ms          154\nBM_neujson_read_parse_pretty_write_string/citm_catalog.json         9.44 ms         9.44 ms           72\nBM_nlohmann_read_parse_pretty_write_string/citm_catalog.json        14.2 ms         14.2 ms           50\nBM_rapidjson_read_parse_pretty_write_string/citm_catalog.json       4.19 ms         4.19 ms          167\nBM_neujson_read_parse/canada.json                                   31.6 ms         31.6 ms           22\nBM_nlohmann_read_parse/canada.json                                  39.1 ms         39.1 ms           18\nBM_rapidjson_read_parse/canada.json                                 3.38 ms         3.38 ms          207\nBM_neujson_read_parse_write_file/canada.json                        68.2 ms         68.2 ms           10\nBM_nlohmann_read_parse_write_file/canada.json                       47.6 ms         47.6 ms           15\nBM_rapidjson_read_parse_write_file/canada.json                      12.5 ms         12.5 ms           55\nBM_neujson_read_parse_write_string/canada.json                      69.4 ms         69.4 ms           10\nBM_nlohmann_read_parse_write_string/canada.json                     48.5 ms         48.5 ms           14\nBM_rapidjson_read_parse_write_string/canada.json                    10.7 ms         10.7 ms           63\nBM_neujson_read_parse_pretty_write_file/canada.json                 72.3 ms         72.3 ms           10\nBM_nlohmann_read_parse_pretty_write_file/canada.json                51.2 ms         51.2 ms           14\nBM_rapidjson_read_parse_pretty_write_file/canada.json               13.7 ms         13.7 ms           51\nBM_neujson_read_parse_pretty_write_string/canada.json               75.9 ms         75.9 ms            9\nBM_nlohmann_read_parse_pretty_write_string/canada.json              55.0 ms         55.0 ms           13\nBM_rapidjson_read_parse_pretty_write_string/canada.json             12.4 ms         12.4 ms           56\n```\n\nThe followings are some snapshots from the results of i5-9500 with gcc 8.5.0 (Red Hat 8.5.0-10) in CentOS-8-Stream\n\n```bash\nRun on (6 X 4166.48 MHz CPU s)\nCPU Caches:\n  L1 Data 32 KiB (x6)\n  L1 Instruction 32 KiB (x6)\n  L2 Unified 256 KiB (x6)\n  L3 Unified 9216 KiB (x1)\nLoad Average: 0.80, 0.52, 0.45\n--------------------------------------------------------------------------------------------------------\nBenchmark                                                              Time             CPU   Iterations\n--------------------------------------------------------------------------------------------------------\nBM_neujson_read_parse/citm_catalog.json                             8.59 ms         8.58 ms           74\nBM_nlohmann_read_parse/citm_catalog.json                            14.7 ms         14.6 ms           48\nBM_rapidjson_read_parse/citm_catalog.json                           2.38 ms         2.37 ms          293\nBM_neujson_read_parse_write_file/citm_catalog.json                  10.1 ms         10.1 ms           70\nBM_nlohmann_read_parse_write_file/citm_catalog.json                 17.5 ms         17.5 ms           40\nBM_rapidjson_read_parse_write_file/citm_catalog.json                3.39 ms         3.39 ms          206\nBM_neujson_read_parse_write_string/citm_catalog.json                10.9 ms         10.9 ms           65\nBM_nlohmann_read_parse_write_string/citm_catalog.json               17.5 ms         17.5 ms           40\nBM_rapidjson_read_parse_write_string/citm_catalog.json              3.20 ms         3.19 ms          218\nBM_neujson_read_parse_pretty_write_file/citm_catalog.json           11.3 ms         11.3 ms           60\nBM_nlohmann_read_parse_pretty_write_file/citm_catalog.json          18.8 ms         18.7 ms           38\nBM_rapidjson_read_parse_pretty_write_file/citm_catalog.json         3.70 ms         3.69 ms          189\nBM_neujson_read_parse_pretty_write_string/citm_catalog.json         14.5 ms         14.5 ms           49\nBM_nlohmann_read_parse_pretty_write_string/citm_catalog.json        18.5 ms         18.5 ms           38\nBM_rapidjson_read_parse_pretty_write_string/citm_catalog.json       3.57 ms         3.57 ms          196\nBM_neujson_read_parse/canada.json                                   27.8 ms         27.7 ms           25\nBM_nlohmann_read_parse/canada.json                                  41.8 ms         41.8 ms           17\nBM_rapidjson_read_parse/canada.json                                 4.59 ms         4.58 ms          152\nBM_neujson_read_parse_write_file/canada.json                         100 ms          100 ms            7\nBM_nlohmann_read_parse_write_file/canada.json                       53.5 ms         53.4 ms           13\nBM_rapidjson_read_parse_write_file/canada.json                      13.6 ms         13.6 ms           51\nBM_neujson_read_parse_write_string/canada.json                       106 ms          106 ms            7\nBM_nlohmann_read_parse_write_string/canada.json                     53.3 ms         53.3 ms           13\nBM_rapidjson_read_parse_write_string/canada.json                    11.9 ms         11.9 ms           58\nBM_neujson_read_parse_pretty_write_file/canada.json                  106 ms          106 ms            7\nBM_nlohmann_read_parse_pretty_write_file/canada.json                58.6 ms         58.6 ms           12\nBM_rapidjson_read_parse_pretty_write_file/canada.json               14.4 ms         14.4 ms           49\nBM_neujson_read_parse_pretty_write_string/canada.json                119 ms          119 ms            6\nBM_nlohmann_read_parse_pretty_write_string/canada.json              64.9 ms         64.8 ms           11\nBM_rapidjson_read_parse_pretty_write_string/canada.json             12.8 ms         12.8 ms           54\n```\n\n## Reference\n\n[RapidJSON](https://github.com/Tencent/rapidjson): A fast JSON parser/generator for C++ with both SAX/DOM style API\n\n## Acknowledgment\n\n![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)\n\nSpecial thanks to [JetBrains](https://www.jetbrains.com/) for licensing free `All Products Pack` for this open source projects\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://homing.so\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/14991225?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eHoming So\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/hominsu/neujson/commits?author=hominsu\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/hominsu/neujson/commits?author=hominsu\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#design-hominsu\" title=\"Design\"\u003e🎨\u003c/a\u003e \u003ca href=\"#example-hominsu\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"#infra-hominsu\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"#platform-hominsu\" title=\"Packaging/porting to new platform\"\u003e📦\u003c/a\u003e \u003ca href=\"https://github.com/hominsu/neujson/commits?author=hominsu\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## License\n\nDistributed under the MIT license. See `LICENSE` for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhominsu%2Fneujson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhominsu%2Fneujson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhominsu%2Fneujson/lists"}