Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

json

> 编程语言
Open source

JSON for Modern C++

50.3K stars0 likes1 views
WebsiteGitHub

About

JSON for Modern C++

  • Design goals
  • Sponsors
  • Support (documentation, FAQ, discussions, API, bug issues)
  • Quick reference
  • Examples
    • Read JSON from a file
    • Creating json objects from JSON literals
    • JSON as a first-class data type
    • Serialization / Deserialization
    • STL-like access
    • Conversion from STL containers
    • JSON Pointer and JSON Patch
    • JSON Merge Patch
    • Implicit conversions
    • Conversions to/from arbitrary types
    • Specializing enum conversion
    • Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)
  • Customers
  • Ecosystem
  • Supported compilers
  • Integration
    • CMake
    • Package Managers
    • Pkg-config
  • License
  • Contact
  • Thanks
  • Used third-party tools
  • Notes
  • Execute unit tests

Design goals

There are myriads of JSON libraries out there, and each may even have its reason to exist. Our class had these design goals:

  • Intuitive syntax. In languages such as Python, JSON feels like a first-class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the examples below and you'll know what I mean.

  • Trivial integration. Our whole code consists of a single header file json.hpp. That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. The library is also included in all popular package managers.

  • Serious testing. Our code is heavily unit-tested and covers 100% of the code, including all exceptional behavior. Furthermore, we checked with Valgrind and the Clang Sanitizers that there are no memory leaks. Google OSS-Fuzz additionally runs fuzz tests against all parsers 24/7, effectively executing billions of tests so far. To maintain high quality, the project is following the Core Infrastructure Initiative (CII) best practices. See the quality assurance overview documentation.

Other aspects were not so important to us:

  • Memory efficiency. Each JSON object has an overhead of one pointer (the maximal size of a union) and one enumeration element (1 byte). The default generalization uses the following C++ data types: std::string for strings, int64_t, uint64_t or double for numbers, std::map for objects, std::vector for arrays, and bool for Booleans. However, you can template the generalized class basic_json to your needs.

  • Speed. There are certainly faster JSON libraries out there. However, if your goal is to speed up your development by adding JSON support with a single header, then this library is the way to go. If you know how to use a std::vector or std::map, you are already set.

See the contribution guidelines for more information.

Sponsors

You can sponsor this library at GitHub Sponsors.

:raising_hand: Priority Sponsor

  • Martti Laine
  • Paul Harrington
  • Mercedes-Benz Group
  • Ryan McCaffery

:label: Named Sponsors

  • Michael Hartmann
  • Stefan Hagen
  • Steve Sperandeo
  • Robert Jefe Lindstädt
  • Steve Wagner

Further support

The development of the library is further supported by JetBrains by providing free access to their IDE tools. Thanks everyone!

Support

:question: If you have a question, please check if it is already answered in the FAQ or the Q&A section. If not, please ask a new question there.

:books: If you want to learn more about how to use the library, check out the rest of the README, have a look at code examples, or browse through the help pages.

:construction: If you want to understand the API better, check out the API Reference or have a look at the quick reference below.

:bug: If you found a bug, please check the FAQ if it is a known issue or the result of a design decision. Please also have a look at the issue list before you create a new issue. Please provide as much information as possible to help us understand and reproduce your issue.

There is also a docset for the documentation browsers Dash, Velocity, and Zeal that contains the full documentation as an offline resource.

Quick reference

  • Constructors basic_json, array, binary, object
  • Object inspection: type, operator value_t, type_name, is_primitive, is_structured, is_null, is_boolean, is_number, is_number_integer, is_number_unsigned, is_number_float, is_object, is_array, is_string, is_binary, is_discarded
  • Value access; get, get_to, get_ptr, get_ref, operator ValueType, get_binary
  • Element access: at, operator[], value, front, back
  • Lookup: find, count, contains
  • Iterators: begin, cbegin, end, cend, rbegin, rend, crbegin, crend, items
  • Capacity: empty, size, max_size
  • Modifiers: clear, push_back, operator+=, emplace_back, emplace, erase, insert, update, swap
  • Lexicographical comparison operators: operator==, operator!=, operator<, operator>, operator<=, operator>=, operator<=>
  • Serialization / Dumping: dump
  • Deserialization / Parsing: parse, accept, sax_parse
  • JSON Pointer functions: flatten, unflatten
  • JSON Patch functions: patch, patch_inplace, diff, merge_patch
  • Static functions: meta, get_allocator
  • Binary formats: from_bjdata, from_bson, from_cbor, from_msgpack, from_ubjson,

Issues· 66 open

View all issuesOpen on GitHub
  • #5393

    Stack overflow in diff(), merge_patch(), and flatten() due to unbounded recursion

    Updated Sep 28, 2026
  • #5294

    Ideas: exploring ways to reduce compilation time

    Updated Sep 28, 2026
  • #5298

    Idea: arena / PMR document mode (O(1) teardown, allocation-free destruction)

    Updated Sep 28, 2026
  • #3578

    Unable to use gnu mpz types for NumberIntegerType

    kind: bugstate: staleUpdated Sep 28, 2026
  • #3583

    json destructor quite slow

    kind: bugstate: staleUpdated Sep 28, 2026
  • #1170

    Custom Precision on floating point numbers

    state: waiting for PRUpdated Sep 28, 2026
  • #5418

    Test suite: reduce runtime — 52 % is Unicode byte sweeps, plus redundant re-parsing in binary roundtrip tests

    solution: proposed fixUpdated Sep 27, 2026
  • #5392

    Stack overflow in binary format writers (CBOR/MessagePack/UBJSON/BSON) due to unbounded recursion

    Updated Sep 27, 2026
  • #2226

    std::tuple dangling reference - implicit conversion

    kind: bugsolution: proposed fixUpdated Sep 27, 2026
  • #3669

    invalid use of incomplete type (boost::optional) / compile error

    kind: bugsolution: proposed fixUpdated Sep 27, 2026

> Tags

C++bsoncborheader-onlyjson

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言