{"id":13424518,"url":"https://github.com/ibireme/yyjson","last_synced_at":"2025-05-13T17:08:22.006Z","repository":{"id":38745420,"uuid":"302298095","full_name":"ibireme/yyjson","owner":"ibireme","description":"The fastest JSON library in C","archived":false,"fork":false,"pushed_at":"2025-04-23T16:24:18.000Z","size":3034,"stargazers_count":3298,"open_issues_count":17,"forks_count":283,"subscribers_count":64,"default_branch":"master","last_synced_at":"2025-04-23T23:16:04.934Z","etag":null,"topics":["c","cross-platform","deserialization","json","portable","pure-c","serialization"],"latest_commit_sha":null,"homepage":"https://ibireme.github.io/yyjson/doc/doxygen/html/","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/ibireme.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2020-10-08T09:54:52.000Z","updated_at":"2025-04-23T13:58:06.000Z","dependencies_parsed_at":"2023-02-14T08:31:14.049Z","dependency_job_id":"855b3dee-5b88-468e-94e9-ab942d939efb","html_url":"https://github.com/ibireme/yyjson","commit_stats":{"total_commits":388,"total_committers":28,"mean_commits":"13.857142857142858","dds":"0.17525773195876293","last_synced_commit":"c3af82ba8d72125469d956fe8c9f0de5b3b8f5e7"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2Fyyjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2Fyyjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2Fyyjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibireme%2Fyyjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibireme","download_url":"https://codeload.github.com/ibireme/yyjson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528900,"owners_count":21445519,"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":["c","cross-platform","deserialization","json","portable","pure-c","serialization"],"created_at":"2024-07-31T00:00:55.508Z","updated_at":"2025-04-23T23:16:10.400Z","avatar_url":"https://github.com/ibireme.png","language":"C","readme":"\n# Introduction\n\n[![Build](https://img.shields.io/github/actions/workflow/status/ibireme/yyjson/cmake.yml?branch=master\u0026style=flat-square)](https://github.com/ibireme/yyjson/actions/workflows/cmake.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/ibireme/yyjson/master?style=flat-square)](https://codecov.io/gh/ibireme/yyjson)\n[![License](https://img.shields.io/github/license/ibireme/yyjson?color=blue\u0026style=flat-square)](https://github.com/ibireme/yyjson/blob/master/LICENSE)\n[![Version](https://img.shields.io/github/v/release/ibireme/yyjson?color=orange\u0026style=flat-square)](https://github.com/ibireme/yyjson/releases)\n[![Packaging status](https://img.shields.io/repology/repositories/yyjson.svg?style=flat-square)](https://repology.org/project/yyjson/versions)\n\nA high performance JSON library written in ANSI C.\n\n# Features\n- **Fast**: can read or write gigabytes per second JSON data on modern CPUs.\n- **Portable**: complies with ANSI C (C89) for cross-platform compatibility.\n- **Strict**: complies with [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259) JSON standard, ensuring strict number format and UTF-8 validation.\n- **Extendable**: offers options to allow comments, trailing commas, NaN/Inf, and custom memory allocator.\n- **Accuracy**: can accurately read and write `int64`, `uint64`, and `double` numbers.\n- **Flexible**: supports unlimited JSON nesting levels, `\\u0000` characters, and non null-terminated strings.\n- **Manipulation**: supports querying and modifying using [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901), [JSON Patch](https://datatracker.ietf.org/doc/html/rfc6902) and [JSON Merge Patch](https://datatracker.ietf.org/doc/html/rfc7386).\n- **Developer-Friendly**: easy integration with only one `h` and one `c` file.\n\n# Limitations\n- An array or object is stored as a [data structure](https://ibireme.github.io/yyjson/doc/doxygen/html/md_doc__data_structure.html) such as linked list, which makes accessing elements by index or key slower than using an iterator.\n- Duplicate keys are allowed in an object, and the order of the keys is preserved.\n- JSON parsing result is immutable, requiring a `mutable copy` for modification.\n\n# Performance\nBenchmark project and dataset: [yyjson_benchmark](https://github.com/ibireme/yyjson_benchmark)\n\nThe simdjson's new `On Demand` API is faster if most JSON fields are known at compile-time.\nThis benchmark project only checks the DOM API, a new benchmark will be added later.\n\n#### AWS EC2 (AMD EPYC 7R32, gcc 9.3)\n![ec2_chart](doc/images/perf_reader_ec2.svg)\n\n|twitter.json|parse (GB/s)|stringify (GB/s)|\n|---|---|---|\n|yyjson(insitu)|1.80|1.51|\n|yyjson|1.72|1.42|\n|simdjson|1.52|0.61|\n|sajson|1.16|   |\n|rapidjson(insitu)|0.77|   |\n|rapidjson(utf8)|0.26|0.39|\n|cjson|0.32|0.17|\n|jansson|0.05|0.11|\n\n\n#### iPhone (Apple A14, clang 12)\n![a14_chart](doc/images/perf_reader_a14.svg)\n\n|twitter.json|parse (GB/s)|stringify (GB/s)|\n|---|---|---|\n|yyjson(insitu)|3.51|2.41|\n|yyjson|2.39|2.01|\n|simdjson|2.19|0.80|\n|sajson|1.74||\n|rapidjson(insitu)|0.75| |\n|rapidjson(utf8)|0.30|0.58|\n|cjson|0.48|0.33|\n|jansson|0.09|0.24|\n\nMore benchmark reports with interactive charts (update 2020-12-12)\n\n|Platform|CPU|Compiler|OS|Report|\n|---|---|---|---|---|\n|Intel NUC 8i5|Core i5-8259U|msvc 2019|Windows 10 2004|[Charts](https://ibireme.github.io/yyjson_benchmark/reports/Intel_NUC_8i5_msvc_2019.html)|\n|Intel NUC 8i5|Core i5-8259U|clang 10.0|Ubuntu 20.04|[Charts](https://ibireme.github.io/yyjson_benchmark/reports/Intel_NUC_8i5_clang_10.html)|\n|Intel NUC 8i5|Core i5-8259U|gcc 9.3|Ubuntu 20.04|[Charts](https://ibireme.github.io/yyjson_benchmark/reports/Intel_NUC_8i5_gcc_9.html)|\n|AWS EC2 c5a.large|AMD EPYC 7R32|gcc 9.3|Ubuntu 20.04|[Charts](https://ibireme.github.io/yyjson_benchmark/reports/EC2_c5a.large_gcc_9.html)|\n|AWS EC2 t4g.medium|Graviton2 (ARM64)|gcc 9.3|Ubuntu 20.04|[Charts](https://ibireme.github.io/yyjson_benchmark/reports/EC2_t4g.medium_gcc_9.html)|\n|Apple iPhone 12 Pro|A14 (ARM64)|clang 12.0|iOS 14|[Charts](https://ibireme.github.io/yyjson_benchmark/reports/Apple_A14_clang_12.html)|\n\n### For better performance, yyjson prefers:\n* A modern processor with:\n    * high instruction level parallelism\n    * excellent branch predictor\n    * low penalty for misaligned memory access\n* A modern compiler with good optimizer (e.g. clang)\n\n\n# Sample Code\n\n### Read JSON string\n```c\nconst char *json = \"{\\\"name\\\":\\\"Mash\\\",\\\"star\\\":4,\\\"hits\\\":[2,2,1,3]}\";\n\n// Read JSON and get root\nyyjson_doc *doc = yyjson_read(json, strlen(json), 0);\nyyjson_val *root = yyjson_doc_get_root(doc);\n\n// Get root[\"name\"]\nyyjson_val *name = yyjson_obj_get(root, \"name\");\nprintf(\"name: %s\\n\", yyjson_get_str(name));\nprintf(\"name length:%d\\n\", (int)yyjson_get_len(name));\n\n// Get root[\"star\"]\nyyjson_val *star = yyjson_obj_get(root, \"star\");\nprintf(\"star: %d\\n\", (int)yyjson_get_int(star));\n\n// Get root[\"hits\"], iterate over the array\nyyjson_val *hits = yyjson_obj_get(root, \"hits\");\nsize_t idx, max;\nyyjson_val *hit;\nyyjson_arr_foreach(hits, idx, max, hit) {\n    printf(\"hit%d: %d\\n\", (int)idx, (int)yyjson_get_int(hit));\n}\n\n// Free the doc\nyyjson_doc_free(doc);\n\n// All functions accept NULL input, and return NULL on error.\n```\n\n### Write JSON string\n```c\n// Create a mutable doc\nyyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);\nyyjson_mut_val *root = yyjson_mut_obj(doc);\nyyjson_mut_doc_set_root(doc, root);\n\n// Set root[\"name\"] and root[\"star\"]\nyyjson_mut_obj_add_str(doc, root, \"name\", \"Mash\");\nyyjson_mut_obj_add_int(doc, root, \"star\", 4);\n\n// Set root[\"hits\"] with an array\nint hits_arr[] = {2, 2, 1, 3};\nyyjson_mut_val *hits = yyjson_mut_arr_with_sint32(doc, hits_arr, 4);\nyyjson_mut_obj_add_val(doc, root, \"hits\", hits);\n\n// To string, minified\nconst char *json = yyjson_mut_write(doc, 0, NULL);\nif (json) {\n    printf(\"json: %s\\n\", json); // {\"name\":\"Mash\",\"star\":4,\"hits\":[2,2,1,3]}\n    free((void *)json);\n}\n\n// Free the doc\nyyjson_mut_doc_free(doc);\n```\n\n### Read JSON file with options\n```c\n// Read JSON file, allowing comments and trailing commas\nyyjson_read_flag flg = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS;\nyyjson_read_err err;\nyyjson_doc *doc = yyjson_read_file(\"/tmp/config.json\", flg, NULL, \u0026err);\n\n// Iterate over the root object\nif (doc) {\n    yyjson_val *obj = yyjson_doc_get_root(doc);\n    yyjson_obj_iter iter;\n    yyjson_obj_iter_init(obj, \u0026iter);\n    yyjson_val *key, *val;\n    while ((key = yyjson_obj_iter_next(\u0026iter))) {\n        val = yyjson_obj_iter_get_val(key);\n        printf(\"%s: %s\\n\", yyjson_get_str(key), yyjson_get_type_desc(val));\n    }\n} else {\n    printf(\"read error (%u): %s at position: %ld\\n\", err.code, err.msg, err.pos);\n}\n\n// Free the doc\nyyjson_doc_free(doc);\n```\n\n### Write JSON file with options\n```c\n// Read the JSON file as a mutable doc\nyyjson_doc *idoc = yyjson_read_file(\"/tmp/config.json\", 0, NULL, NULL);\nyyjson_mut_doc *doc = yyjson_doc_mut_copy(idoc, NULL);\nyyjson_mut_val *obj = yyjson_mut_doc_get_root(doc);\n\n// Remove null values in root object\nyyjson_mut_obj_iter iter;\nyyjson_mut_obj_iter_init(obj, \u0026iter);\nyyjson_mut_val *key, *val;\nwhile ((key = yyjson_mut_obj_iter_next(\u0026iter))) {\n    val = yyjson_mut_obj_iter_get_val(key);\n    if (yyjson_mut_is_null(val)) {\n        yyjson_mut_obj_iter_remove(\u0026iter);\n    }\n}\n\n// Write the json pretty, escape unicode\nyyjson_write_flag flg = YYJSON_WRITE_PRETTY | YYJSON_WRITE_ESCAPE_UNICODE;\nyyjson_write_err err;\nyyjson_mut_write_file(\"/tmp/config.json\", doc, flg, NULL, \u0026err);\nif (err.code) {\n    printf(\"write error (%u): %s\\n\", err.code, err.msg);\n}\n\n// Free the doc\nyyjson_doc_free(idoc);\nyyjson_mut_doc_free(doc);\n```\n\n# Documentation\nThe latest (unreleased) documentation can be accessed in the [doc](https://github.com/ibireme/yyjson/tree/master/doc) directory.\nThe pre-generated Doxygen HTML for the release version can be viewed here:\n* [Home Page](https://ibireme.github.io/yyjson/doc/doxygen/html/)\n    * [Build and test](https://ibireme.github.io/yyjson/doc/doxygen/html/md_doc__build_and_test.html)\n    * [API and sample code](https://ibireme.github.io/yyjson/doc/doxygen/html/md_doc__a_p_i.html)\n    * [Data structure](https://ibireme.github.io/yyjson/doc/doxygen/html/md_doc__data_structure.html)\n    * [Changelog](https://ibireme.github.io/yyjson/doc/doxygen/html/md__c_h_a_n_g_e_l_o_g.html)\n\n# Packaging status\n\n[![Packaging status](https://repology.org/badge/vertical-allrepos/yyjson.svg)](https://repology.org/project/yyjson/versions)\n\n# Built With yyjson\n\nA non-exhaustive list of projects that expose yyjson to other languages or\nuse yyjson internally for a major feature. If you have a project that uses\nyyjson, feel free to open a PR to add it to this list.\n\n| Project         | Language | Description                                                                              |\n|-----------------|----------|------------------------------------------------------------------------------------------|\n| [py_yyjson][]   | Python   | Python bindings for yyjson                                                               |\n| [orjson][]      | Python   | JSON library for Python with an optional yyjson backend                                  |\n| [cpp-yyjson][]  | C++      | C++ JSON library with a yyjson backend                                                   |\n| [reflect-cpp][] | C++      | C++ library for serialization through automated field name retrieval from structs        |\n| [yyjsonr][]     | R        | R binding for yyjson                                                                     |\n| [Ananda][]      | Swift    | JSON model decoding based on yyjson                                                      |\n| [duckdb][]      | C++      | DuckDB is an in-process SQL OLAP Database Management System                              |\n| [fastfetch][]   | C        | A neofetch-like tool for fetching system information and displaying them in a pretty way |\n| [Zrythm][]      | C        | Digital Audio Workstation that uses yyjson to serialize JSON project files               |\n| [bemorehuman][] | C        | Recommendation engine with a focus on uniqueness of the person receiving the rec         |\n| [mruby-yyjson][]| mruby    | Efficient JSON parsing and serialization library for mruby using yyjson                  |\n| [YYJSON.jl][]   | Julia    | Julia bindings for yyjson                                                                |\n\n# TODO for v1.0\n* [x] Add documentation page.\n* [x] Add GitHub workflow for CI and codecov.\n* [x] Add more tests: valgrind, sanitizer, fuzzing.\n* [x] Support JSON Pointer to query and modify JSON.\n* [x] Add `RAW` type for JSON reader and writer.\n* [x] Add option to limit real number output precision.\n* [ ] Add option to support JSON5 (if feasible).\n* [ ] Add functions to diff two JSON documents.\n* [ ] Add documentation on performance optimizations.\n* [ ] Ensure ABI stability.\n\n# License\nThis project is released under the MIT license.\n\n[py_yyjson]: https://github.com/tktech/py_yyjson\n[orjson]: https://github.com/ijl/orjson\n[cpp-yyjson]: https://github.com/yosh-matsuda/cpp-yyjson\n[reflect-cpp]: https://github.com/getml/reflect-cpp\n[yyjsonr]: https://github.com/coolbutuseless/yyjsonr\n[Ananda]: https://github.com/nixzhu/Ananda\n[duckdb]: https://github.com/duckdb/duckdb\n[fastfetch]: https://github.com/fastfetch-cli/fastfetch\n[Zrythm]: https://github.com/zrythm/zrythm\n[bemorehuman]: https://github.com/BeMoreHumanOrg/bemorehuman\n[mruby-yyjson]: https://github.com/buty4649/mruby-yyjson\n[YYJSON.jl]: https://github.com/bhftbootcamp/YYJSON.jl\n","funding_links":[],"categories":["JSON","C","File Formats"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibireme%2Fyyjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibireme%2Fyyjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibireme%2Fyyjson/lists"}