[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-725":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":23,"hasPages":25,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":45,"readmeContent":46,"aiSummary":47,"trendingCount":16,"starSnapshotCount":16,"syncStatus":48,"lastSyncTime":49,"discoverSource":50},725,"json","nlohmann\u002Fjson","nlohmann","JSON for Modern C++","https:\u002F\u002Fjson.nlohmann.me",null,"C++",49911,7412,754,26,0,10,43,299,42,120,"MIT License",false,"develop",true,[27,28,29,5,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44],"bson","cbor","header-only","json-diff","json-merge-patch","json-parser","json-patch","json-pointer","json-serialization","messagepack","msgpack","rfc-6901","rfc-6902","rfc-7049","rfc-7159","rfc-8259","stl-containers","ubjson","2026-06-12 04:00:05","[![JSON for Modern C++](docs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fjson.gif)](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Freleases)\n\n[![Build Status](https:\u002F\u002Fci.appveyor.com\u002Fapi\u002Fprojects\u002Fstatus\u002F1acb366xfyg3qybk\u002Fbranch\u002Fdevelop?svg=true)](https:\u002F\u002Fci.appveyor.com\u002Fproject\u002Fnlohmann\u002Fjson)\n[![Ubuntu](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fworkflows\u002FUbuntu\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Factions?query=workflow%3AUbuntu)\n[![macOS](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fworkflows\u002FmacOS\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Factions?query=workflow%3AmacOS)\n[![Windows](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fworkflows\u002FWindows\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Factions?query=workflow%3AWindows)\n[![Coverage Status](https:\u002F\u002Fcoveralls.io\u002Frepos\u002Fgithub\u002Fnlohmann\u002Fjson\u002Fbadge.svg?branch=develop)](https:\u002F\u002Fcoveralls.io\u002Fgithub\u002Fnlohmann\u002Fjson?branch=develop)\n[![Coverity Scan Build Status](https:\u002F\u002Fscan.coverity.com\u002Fprojects\u002F5550\u002Fbadge.svg)](https:\u002F\u002Fscan.coverity.com\u002Fprojects\u002Fnlohmann-json)\n[![Codacy Badge](https:\u002F\u002Fapp.codacy.com\u002Fproject\u002Fbadge\u002FGrade\u002Fe0d1a9d5d6fd46fcb655c4cb930bb3e8)](https:\u002F\u002Fapp.codacy.com\u002Fgh\u002Fnlohmann\u002Fjson\u002Fdashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)\n[![Cirrus CI](https:\u002F\u002Fapi.cirrus-ci.com\u002Fgithub\u002Fnlohmann\u002Fjson.svg)](https:\u002F\u002Fcirrus-ci.com\u002Fgithub\u002Fnlohmann\u002Fjson)\n[![Fuzzing Status](https:\u002F\u002Foss-fuzz-build-logs.storage.googleapis.com\u002Fbadges\u002Fjson.svg)](https:\u002F\u002Fbugs.chromium.org\u002Fp\u002Foss-fuzz\u002Fissues\u002Flist?sort=-opened&can=1&q=proj:json)\n[![Try online](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Ftry-online-blue.svg)](https:\u002F\u002Fwandbox.org\u002Fpermlink\u002F1mp10JbaANo6FUc7)\n[![Documentation](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fdocs-mkdocs-blue.svg)](https:\u002F\u002Fjson.nlohmann.me)\n[![GitHub license](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-blue.svg)](https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Fmaster\u002FLICENSE.MIT)\n[![GitHub Releases](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frelease\u002Fnlohmann\u002Fjson.svg)](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Freleases)\n[![Packaging status](https:\u002F\u002Frepology.org\u002Fbadge\u002Ftiny-repos\u002Fnlohmann-json.svg)](https:\u002F\u002Frepology.org\u002Fproject\u002Fnlohmann-json\u002Fversions)\n[![GitHub Downloads](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fdownloads\u002Fnlohmann\u002Fjson\u002Ftotal)](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Freleases)\n[![GitHub Issues](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fissues\u002Fnlohmann\u002Fjson.svg)](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues)\n[![Average time to resolve an issue](https:\u002F\u002Fisitmaintained.com\u002Fbadge\u002Fresolution\u002Fnlohmann\u002Fjson.svg)](https:\u002F\u002Fisitmaintained.com\u002Fproject\u002Fnlohmann\u002Fjson \"Average time to resolve an issue\")\n[![CII Best Practices](https:\u002F\u002Fbestpractices.coreinfrastructure.org\u002Fprojects\u002F289\u002Fbadge)](https:\u002F\u002Fbestpractices.coreinfrastructure.org\u002Fprojects\u002F289)\n[![OpenSSF Scorecard](https:\u002F\u002Fapi.scorecard.dev\u002Fprojects\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fbadge)](https:\u002F\u002Fscorecard.dev\u002Fviewer\u002F?uri=github.com\u002Fnlohmann\u002Fjson)\n[![Backup Status](https:\u002F\u002Fapp.cloudback.it\u002Fbadge\u002Fnlohmann\u002Fjson)](https:\u002F\u002Fcloudback.it)\n[![GitHub Sponsors](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGitHub-Sponsors-ff69b4)](https:\u002F\u002Fgithub.com\u002Fsponsors\u002Fnlohmann)\n[![REUSE status](https:\u002F\u002Fapi.reuse.software\u002Fbadge\u002Fgithub.com\u002Fnlohmann\u002Fjson)](https:\u002F\u002Fapi.reuse.software\u002Finfo\u002Fgithub.com\u002Fnlohmann\u002Fjson)\n[![Discord](https:\u002F\u002Fimg.shields.io\u002Fdiscord\u002F1003743314341793913)](https:\u002F\u002Fdiscord.gg\u002F6mrGXKvX7y)\n\n- [Design goals](#design-goals)\n- [Sponsors](#sponsors)\n- [Support](#support) ([documentation](https:\u002F\u002Fjson.nlohmann.me), [FAQ](https:\u002F\u002Fjson.nlohmann.me\u002Fhome\u002Ffaq\u002F), [discussions](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fdiscussions), [API](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002F), [bug issues](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues))\n- [Quick reference](#quick-reference)\n- [Examples](#examples)\n  - [Read JSON from a file](#read-json-from-a-file)\n  - [Creating `json` objects from JSON literals](#creating-json-objects-from-json-literals)\n  - [JSON as a first-class data type](#json-as-a-first-class-data-type)\n  - [Serialization \u002F Deserialization](#serialization--deserialization)\n  - [STL-like access](#stl-like-access)\n  - [Conversion from STL containers](#conversion-from-stl-containers)\n  - [JSON Pointer and JSON Patch](#json-pointer-and-json-patch)\n  - [JSON Merge Patch](#json-merge-patch)\n  - [Implicit conversions](#implicit-conversions)\n  - [Conversions to\u002Ffrom arbitrary types](#arbitrary-types-conversions)\n  - [Specializing enum conversion](#specializing-enum-conversion)\n  - [Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)](#binary-formats-bson-cbor-messagepack-ubjson-and-bjdata)\n- [Customers](#customers)\n- [Supported compilers](#supported-compilers)\n- [Integration](#integration)\n  - [CMake](#cmake)\n  - [Package Managers](#package-managers)\n  - [Pkg-config](#pkg-config)\n- [License](#license)\n- [Contact](#contact)\n- [Thanks](#thanks)\n- [Used third-party tools](#used-third-party-tools)\n- [Notes](#notes)\n- [Execute unit tests](#execute-unit-tests)\n\n## Design goals\n\nThere are myriads of [JSON](https:\u002F\u002Fjson.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:\n\n- **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](#examples) and you'll know what I mean.\n\n- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fblob\u002Fdevelop\u002Fsingle_include\u002Fnlohmann\u002Fjson.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](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F).\n\n- **Serious testing**. Our code is heavily [unit-tested](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Ftree\u002Fdevelop\u002Ftests\u002Fsrc) and covers [100%](https:\u002F\u002Fcoveralls.io\u002Fr\u002Fnlohmann\u002Fjson) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](https:\u002F\u002Fvalgrind.org) and the [Clang Sanitizers](https:\u002F\u002Fclang.llvm.org\u002Fdocs\u002Findex.html) that there are no memory leaks. [Google OSS-Fuzz](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Foss-fuzz\u002Ftree\u002Fmaster\u002Fprojects\u002Fjson) additionally runs fuzz tests against all parsers 24\u002F7, effectively executing billions of tests so far. To maintain high quality, the project is following the [Core Infrastructure Initiative (CII) best practices](https:\u002F\u002Fbestpractices.coreinfrastructure.org\u002Fprojects\u002F289). See the [quality assurance](https:\u002F\u002Fjson.nlohmann.me\u002Fcommunity\u002Fquality_assurance) overview documentation.\n\nOther aspects were not so important to us:\n\n- **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.\n\n- **Speed**. There are certainly [faster JSON libraries](https:\u002F\u002Fgithub.com\u002Fmiloyip\u002Fnativejson-benchmark#parsing-time) 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.\n\nSee the [contribution guidelines](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fblob\u002Fmaster\u002F.github\u002FCONTRIBUTING.md#please-dont) for more information.\n\n## Sponsors\n\nYou can sponsor this library at [GitHub Sponsors](https:\u002F\u002Fgithub.com\u002Fsponsors\u002Fnlohmann).\n\n### :raising_hand: Priority Sponsor\n\n- [Martti Laine](https:\u002F\u002Fgithub.com\u002Fcodeclown)\n- [Paul Harrington](https:\u002F\u002Fgithub.com\u002Fphrrngtn)\n- [Mercedes-Benz Group](https:\u002F\u002Fgithub.com\u002Fmercedes-benz)\n- [Ryan McCaffery](https:\u002F\u002Fgithub.com\u002Fmccaffers)\n\n### :label: Named Sponsors\n\n- [Michael Hartmann](https:\u002F\u002Fgithub.com\u002FreFX-Mike)\n- [Stefan Hagen](https:\u002F\u002Fgithub.com\u002Fsthagen)\n- [Steve Sperandeo](https:\u002F\u002Fgithub.com\u002Fhomer6)\n- [Robert Jefe Lindstädt](https:\u002F\u002Fgithub.com\u002Feljefedelrodeodeljefe)\n- [Steve Wagner](https:\u002F\u002Fgithub.com\u002Fciroque)\n- [Lion Yang](https:\u002F\u002Fgithub.com\u002FLionNatsu)\n\n### Further support\n\nThe development of the library is further supported by JetBrains by providing free access to their IDE tools.\n\n[![JetBrains logo.](https:\u002F\u002Fresources.jetbrains.com\u002Fstorage\u002Fproducts\u002Fcompany\u002Fbrand\u002Flogos\u002Fjetbrains.svg)](https:\u002F\u002Fjb.gg\u002FOpenSourceSupport)\n\nThanks everyone!\n\n## Support\n\n:question: If you have a **question**, please check if it is already answered in the [**FAQ**](https:\u002F\u002Fjson.nlohmann.me\u002Fhome\u002Ffaq\u002F) or the [**Q&A**](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fdiscussions\u002Fcategories\u002Fq-a) section. If not, please [**ask a new question**](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fdiscussions\u002Fnew) there.\n\n:books: If you want to **learn more** about how to use the library, check out the rest of the [**README**](#examples), have a look at [**code examples**](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Ftree\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fexamples), or browse through the [**help pages**](https:\u002F\u002Fjson.nlohmann.me).\n\n:construction: If you want to understand the **API** better, check out the [**API Reference**](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002F) or have a look at the [quick reference](#quick-reference) below.\n\n:bug: If you found a **bug**, please check the [**FAQ**](https:\u002F\u002Fjson.nlohmann.me\u002Fhome\u002Ffaq\u002F) if it is a known issue or the result of a design decision. Please also have a look at the [**issue list**](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues) before you [**create a new issue**](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues\u002Fnew\u002Fchoose). Please provide as much information as possible to help us understand and reproduce your issue.\n\nThere is also a [**docset**](https:\u002F\u002Fgithub.com\u002FKapeli\u002FDash-User-Contributions\u002Ftree\u002Fmaster\u002Fdocsets\u002FJSON_for_Modern_C%2B%2B) for the documentation browsers [Dash](https:\u002F\u002Fkapeli.com\u002Fdash), [Velocity](https:\u002F\u002Fvelocity.silverlakesoftware.com), and [Zeal](https:\u002F\u002Fzealdocs.org) that contains the full [documentation](https:\u002F\u002Fjson.nlohmann.me) as an offline resource.\n\n## Quick reference\n\n- **Constructors** [basic_json](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fbasic_json), [array](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Farray), [binary](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fbinary), [object](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fobject)\n- **Object inspection**: [type](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ftype), [operator value_t](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_value_t), [type_name](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ftype_name), [is_primitive](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_primitive), [is_structured](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_structured), [is_null](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_null), [is_boolean](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_boolean), [is_number](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_number), [is_number_integer](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_number_integer), [is_number_unsigned](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_number_unsigned), [is_number_float](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_number_float), [is_object](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_object), [is_array](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_array), [is_string](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_string), [is_binary](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_binary), [is_discarded](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fis_discarded)\n- **Value access**; [get](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fget), [get_to](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fget_to), [get_ptr](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fget_ptr), [get_ref](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fget_ref), [operator ValueType](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_ValueType), [get_binary](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fget_binary)\n- **Element access**: [at](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fat), [operator[]](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator[]), [value](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fvalue), [front](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ffront), [back](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fback)\n- **Lookup**: [find](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ffind), [count](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fcount), [contains](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fcontains)\n- **Iterators**: [begin](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fbegin), [cbegin](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fcbegin), [end](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fend), [cend](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fcend), [rbegin](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Frbegin), [rend](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Frend), [crbegin](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fcrbegin), [crend](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fcrend), [items](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fitems)\n- **Capacity**: [empty](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fempty), [size](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fsize), [max_size](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fmax_size)\n- **Modifiers**: [clear](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fclear), [push_back](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fpush_back), [operator+=](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator+=), [emplace_back](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Femplace_back), [emplace](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Femplace), [erase](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ferase), [insert](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Finsert), [update](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fupdate), [swap](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fswap)\n- **Lexicographical comparison operators**: [operator==](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_eq), [operator!=](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_ne), [operator\u003C](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_lt), [operator>](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_gt), [operator\u003C=](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_le), [operator>=](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_ge), [operator\u003C=>](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Foperator_spaceship)\n- **Serialization \u002F Dumping**: [dump](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fdump)\n- **Deserialization \u002F Parsing**: [parse](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fparse), [accept](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Faccept), [sax_parse](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fsax_parse)\n- **JSON Pointer functions**: [flatten](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fflatten), [unflatten](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Funflatten)\n- **JSON Patch functions**: [patch](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fpatch), [patch_inplace](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fpatch_inplace), [diff](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fdiff), [merge_patch](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fmerge_patch)\n- **Static functions**: [meta](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fmeta), [get_allocator](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fget_allocator)\n- **Binary formats**: [from_bjdata](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ffrom_bjdata), [from_bson](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ffrom_bson), [from_cbor](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ffrom_cbor), [from_msgpack](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ffrom_msgpack), [from_ubjson](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Ffrom_ubjson), [to_bjdata](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fto_bjdata), [to_bson](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fto_bson), [to_cbor](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fto_cbor), [to_msgpack](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fto_msgpack), [to_ubjson](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fto_ubjson)\n- **Non-member functions**: [operator\u003C\u003C](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Foperator_ltlt\u002F), [operator>>](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Foperator_gtgt\u002F), [to_string](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fto_string)\n- **Literals**: [operator\"\"_json](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Foperator_literal_json)\n- **Helper classes**: [std::hash&lt;basic_json&gt;](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fstd_hash), [std::swap&lt;basic_json&gt;](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fstd_swap)\n\n[**Full API documentation**](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002F)\n\n## Examples\n\nHere are some examples to give you an idea how to use the class.\n\nBesides the examples below, you may want to:\n\n→ Check the [documentation](https:\u002F\u002Fjson.nlohmann.me\u002F)\\\n→ Browse the [standalone example files](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Ftree\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fexamples)\\\n→ Read the full [API Documentation](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002F) with self-contained examples for every function\n\n### Read JSON from a file\n\nThe `json` class provides an API for manipulating a JSON value. To create a `json` object by reading a JSON file:\n\n```cpp\n#include \u003Cfstream>\n#include \u003Cnlohmann\u002Fjson.hpp>\nusing json = nlohmann::json;\n\n\u002F\u002F ...\n\nstd::ifstream f(\"example.json\");\njson data = json::parse(f);\n```\n\nIf using modules (enabled with `NLOHMANN_JSON_BUILD_MODULES`), this example becomes:\n```cpp\nimport std;\nimport nlohmann.json;\n\nusing json = nlohmann::json;\n\n\u002F\u002F ...\n\nstd::ifstream f(\"example.json\");\njson data = json::parse(f);\n```\n\n### Creating `json` objects from JSON literals\n\nAssume you want to hard-code this literal JSON value as a `json` object:\n\n```json\n{\n  \"pi\": 3.141,\n  \"happy\": true\n}\n```\n\nThere are various options:\n\n```cpp\n\u002F\u002F Using (raw) string literals and json::parse\njson ex1 = json::parse(R\"(\n  {\n    \"pi\": 3.141,\n    \"happy\": true\n  }\n)\");\n\n\u002F\u002F Using user-defined (raw) string literals\nusing namespace nlohmann::literals;\njson ex2 = R\"(\n  {\n    \"pi\": 3.141,\n    \"happy\": true\n  }\n)\"_json;\n\n\u002F\u002F Using initializer lists\njson ex3 = {\n  {\"happy\", true},\n  {\"pi\", 3.141},\n};\n```\n\n### JSON as a first-class data type\n\nHere are some examples to give you an idea how to use the class.\n\nAssume you want to create the JSON object\n\n```json\n{\n  \"pi\": 3.141,\n  \"happy\": true,\n  \"name\": \"Niels\",\n  \"nothing\": null,\n  \"answer\": {\n    \"everything\": 42\n  },\n  \"list\": [1, 0, 2],\n  \"object\": {\n    \"currency\": \"USD\",\n    \"value\": 42.99\n  }\n}\n```\n\nWith this library, you could write:\n\n```cpp\n\u002F\u002F create an empty structure (null)\njson j;\n\n\u002F\u002F add a number stored as double (note the implicit conversion of j to an object)\nj[\"pi\"] = 3.141;\n\n\u002F\u002F add a Boolean stored as bool\nj[\"happy\"] = true;\n\n\u002F\u002F add a string stored as std::string\nj[\"name\"] = \"Niels\";\n\n\u002F\u002F add another null object by passing nullptr\nj[\"nothing\"] = nullptr;\n\n\u002F\u002F add an object inside the object\nj[\"answer\"][\"everything\"] = 42;\n\n\u002F\u002F add an array stored as std::vector (using an initializer list)\nj[\"list\"] = { 1, 0, 2 };\n\n\u002F\u002F add another object (using an initializer list of pairs)\nj[\"object\"] = { {\"currency\", \"USD\"}, {\"value\", 42.99} };\n\n\u002F\u002F instead, you could also write (which looks very similar to the JSON above)\njson j2 = {\n  {\"pi\", 3.141},\n  {\"happy\", true},\n  {\"name\", \"Niels\"},\n  {\"nothing\", nullptr},\n  {\"answer\", {\n    {\"everything\", 42}\n  }},\n  {\"list\", {1, 0, 2}},\n  {\"object\", {\n    {\"currency\", \"USD\"},\n    {\"value\", 42.99}\n  }}\n};\n```\n\nNote that in all these cases, you never need to \"tell\" the compiler which JSON value type you want to use. If you want to be explicit or express some edge cases, the functions [`json::array()`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Farray\u002F) and [`json::object()`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fobject\u002F) will help:\n\n```cpp\n\u002F\u002F a way to express the empty array []\njson empty_array_explicit = json::array();\n\n\u002F\u002F ways to express the empty object {}\njson empty_object_implicit = json({});\njson empty_object_explicit = json::object();\n\n\u002F\u002F a way to express an _array_ of key\u002Fvalue pairs [[\"currency\", \"USD\"], [\"value\", 42.99]]\njson array_not_object = json::array({ {\"currency\", \"USD\"}, {\"value\", 42.99} });\n```\n\n### Serialization \u002F Deserialization\n\n#### To\u002Ffrom strings\n\nYou can create a JSON value (deserialization) by appending `_json` to a string literal:\n\n```cpp\n\u002F\u002F create object from string literal\njson j = \"{ \\\"happy\\\": true, \\\"pi\\\": 3.141 }\"_json;\n\n\u002F\u002F or even nicer with a raw string literal\nauto j2 = R\"(\n  {\n    \"happy\": true,\n    \"pi\": 3.141\n  }\n)\"_json;\n```\n\nNote that without appending the `_json` suffix, the passed string literal is not parsed, but just used as JSON string\nvalue. That is, `json j = \"{ \\\"happy\\\": true, \\\"pi\\\": 3.141 }\"` would just store the string\n`\"{ \"happy\": true, \"pi\": 3.141 }\"` rather than parsing the actual object.\n\nThe string literal should be brought into scope with `using namespace nlohmann::literals;`\n(see [`json::parse()`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Foperator_literal_json\u002F)).\n\nThe above example can also be expressed explicitly using [`json::parse()`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fparse\u002F):\n\n```cpp\n\u002F\u002F parse explicitly\nauto j3 = json::parse(R\"({\"happy\": true, \"pi\": 3.141})\");\n```\n\nYou can also get a string representation of a JSON value (serialize):\n\n```cpp\n\u002F\u002F explicit conversion to string\nstd::string s = j.dump();    \u002F\u002F {\"happy\":true,\"pi\":3.141}\n\n\u002F\u002F serialization with pretty printing\n\u002F\u002F pass in the amount of spaces to indent\nstd::cout \u003C\u003C j.dump(4) \u003C\u003C std::endl;\n\u002F\u002F {\n\u002F\u002F     \"happy\": true,\n\u002F\u002F     \"pi\": 3.141\n\u002F\u002F }\n```\n\nNote the difference between serialization and assignment:\n\n```cpp\n\u002F\u002F store a string in a JSON value\njson j_string = \"this is a string\";\n\n\u002F\u002F retrieve the string value\nauto cpp_string = j_string.get\u003Cstd::string>();\n\u002F\u002F retrieve the string value (alternative when a variable already exists)\nstd::string cpp_string2;\nj_string.get_to(cpp_string2);\n\n\u002F\u002F retrieve the serialized value (explicit JSON serialization)\nstd::string serialized_string = j_string.dump();\n\n\u002F\u002F output of original string\nstd::cout \u003C\u003C cpp_string \u003C\u003C \" == \" \u003C\u003C cpp_string2 \u003C\u003C \" == \" \u003C\u003C j_string.get\u003Cstd::string>() \u003C\u003C '\\n';\n\u002F\u002F output of serialized value\nstd::cout \u003C\u003C j_string \u003C\u003C \" == \" \u003C\u003C serialized_string \u003C\u003C std::endl;\n```\n\n[`.dump()`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fdump\u002F) returns the originally stored string value.\n\nNote the library only supports UTF-8. When you store strings with different encodings in the library, calling [`dump()`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fdump\u002F) may throw an exception unless `json::error_handler_t::replace` or `json::error_handler_t::ignore` are used as error handlers.\n\n#### To\u002Ffrom streams (e.g., files, string streams)\n\nYou can also use streams to serialize and deserialize:\n\n```cpp\n\u002F\u002F deserialize from standard input\njson j;\nstd::cin >> j;\n\n\u002F\u002F serialize to standard output\nstd::cout \u003C\u003C j;\n\n\u002F\u002F the setw manipulator was overloaded to set the indentation for pretty printing\nstd::cout \u003C\u003C std::setw(4) \u003C\u003C j \u003C\u003C std::endl;\n```\n\nThese operators work for any subclasses of `std::istream` or `std::ostream`. Here is the same example with files:\n\n```cpp\n\u002F\u002F read a JSON file\nstd::ifstream i(\"file.json\");\njson j;\ni >> j;\n\n\u002F\u002F write prettified JSON to another file\nstd::ofstream o(\"pretty.json\");\no \u003C\u003C std::setw(4) \u003C\u003C j \u003C\u003C std::endl;\n```\n\nPlease note that setting the exception bit for `failbit` is inappropriate for this use case. It will result in program termination due to the `noexcept` specifier in use.\n\n#### Read from iterator range\n\nYou can also parse JSON from an iterator range; that is, from any container accessible by iterators whose `value_type` is an integral type of 1, 2, or 4 bytes, which will be interpreted as UTF-8, UTF-16, and UTF-32 respectively. For instance, a `std::vector\u003Cstd::uint8_t>`, or a `std::list\u003Cstd::uint16_t>`:\n\n```cpp\nstd::vector\u003Cstd::uint8_t> v = {'t', 'r', 'u', 'e'};\njson j = json::parse(v.begin(), v.end());\n```\n\nYou may leave the iterators for the range [begin, end):\n\n```cpp\nstd::vector\u003Cstd::uint8_t> v = {'t', 'r', 'u', 'e'};\njson j = json::parse(v);\n```\n\n#### Custom data source\n\nSince the parse function accepts arbitrary iterator ranges, you can provide your own data sources by implementing the `LegacyInputIterator` concept.\n\n```cpp\nstruct MyContainer {\n  void advance();\n  const char& get_current();\n};\n\nstruct MyIterator {\n    using difference_type = std::ptrdiff_t;\n    using value_type = char;\n    using pointer = const char*;\n    using reference = const char&;\n    using iterator_category = std::input_iterator_tag;\n\n    MyIterator& operator++() {\n        target->advance();\n        return *this;\n    }\n\n    bool operator!=(const MyIterator& rhs) const {\n        return rhs.target != target;\n    }\n\n    reference operator*() const {\n        return target->get_current();\n    }\n\n    MyContainer* target = nullptr;\n};\n\nMyIterator begin(MyContainer& tgt) {\n    return MyIterator{&tgt};\n}\n\nMyIterator end(const MyContainer&) {\n    return {};\n}\n\nvoid foo() {\n    MyContainer c;\n    json j = json::parse(c);\n}\n```\n\n#### SAX interface\n\nThe library uses a SAX-like interface with the following functions:\n\n```cpp\n\u002F\u002F called when null is parsed\nbool null();\n\n\u002F\u002F called when a boolean is parsed; value is passed\nbool boolean(bool val);\n\n\u002F\u002F called when a signed or unsigned integer number is parsed; value is passed\nbool number_integer(number_integer_t val);\nbool number_unsigned(number_unsigned_t val);\n\n\u002F\u002F called when a floating-point number is parsed; value and original string is passed\nbool number_float(number_float_t val, const string_t& s);\n\n\u002F\u002F called when a string is parsed; value is passed and can be safely moved away\nbool string(string_t& val);\n\u002F\u002F called when a binary value is parsed; value is passed and can be safely moved away\nbool binary(binary_t& val);\n\n\u002F\u002F called when an object or array begins or ends, resp. The number of elements is passed (or -1 if not known)\nbool start_object(std::size_t elements);\nbool end_object();\nbool start_array(std::size_t elements);\nbool end_array();\n\u002F\u002F called when an object key is parsed; value is passed and can be safely moved away\nbool key(string_t& val);\n\n\u002F\u002F called when a parse error occurs; byte position, the last token, and an exception is passed\nbool parse_error(std::size_t position, const std::string& last_token, const detail::exception& ex);\n```\n\nThe return value of each function determines whether parsing should proceed.\n\nTo implement your own SAX handler, proceed as follows:\n\n1. Implement the SAX interface in a class. You can use class `nlohmann::json_sax\u003Cjson>` as base class, but you can also use any class where the functions described above are implemented and public.\n2. Create an object of your SAX interface class, e.g. `my_sax`.\n3. Call `bool json::sax_parse(input, &my_sax)`; where the first parameter can be any input like a string or an input stream and the second parameter is a pointer to your SAX interface.\n\nNote the `sax_parse` function only returns a `bool` indicating the result of the last executed SAX event. It does not return a  `json` value - it is up to you to decide what to do with the SAX events. Furthermore, no exceptions are thrown in case of a parse error -- it is up to you what to do with the exception object passed to your `parse_error` implementation. Internally, the SAX interface is used for the DOM parser (class `json_sax_dom_parser`) as well as the acceptor (`json_sax_acceptor`), see file [`json_sax.hpp`](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fblob\u002Fdevelop\u002Finclude\u002Fnlohmann\u002Fdetail\u002Finput\u002Fjson_sax.hpp).\n\n### STL-like access\n\nWe designed the JSON class to behave just like an STL container. In fact, it satisfies the [**ReversibleContainer**](https:\u002F\u002Fen.cppreference.com\u002Fw\u002Fcpp\u002Fnamed_req\u002FReversibleContainer) requirement.\n\n```cpp\n\u002F\u002F create an array using push_back\njson j;\nj.push_back(\"foo\");\nj.push_back(1);\nj.push_back(true);\n\n\u002F\u002F also use emplace_back\nj.emplace_back(1.78);\n\n\u002F\u002F iterate the array\nfor (json::iterator it = j.begin(); it != j.end(); ++it) {\n  std::cout \u003C\u003C *it \u003C\u003C '\\n';\n}\n\n\u002F\u002F range-based for\nfor (auto& element : j) {\n  std::cout \u003C\u003C element \u003C\u003C '\\n';\n}\n\n\u002F\u002F getter\u002Fsetter\nconst auto tmp = j[0].get\u003Cstd::string>();\nj[1] = 42;\nbool foo = j.at(2);\n\n\u002F\u002F comparison\nj == R\"([\"foo\", 1, true, 1.78])\"_json;  \u002F\u002F true\n\n\u002F\u002F other stuff\nj.size();     \u002F\u002F 4 entries\nj.empty();    \u002F\u002F false\nj.type();     \u002F\u002F json::value_t::array\nj.clear();    \u002F\u002F the array is empty again\n\n\u002F\u002F convenience type checkers\nj.is_null();\nj.is_boolean();\nj.is_number();\nj.is_object();\nj.is_array();\nj.is_string();\n\n\u002F\u002F create an object\njson o;\no[\"foo\"] = 23;\no[\"bar\"] = false;\no[\"baz\"] = 3.141;\n\n\u002F\u002F also use emplace\no.emplace(\"weather\", \"sunny\");\n\n\u002F\u002F special iterator member functions for objects\nfor (json::iterator it = o.begin(); it != o.end(); ++it) {\n  std::cout \u003C\u003C it.key() \u003C\u003C \" : \" \u003C\u003C it.value() \u003C\u003C \"\\n\";\n}\n\n\u002F\u002F the same code as range for\nfor (auto& el : o.items()) {\n  std::cout \u003C\u003C el.key() \u003C\u003C \" : \" \u003C\u003C el.value() \u003C\u003C \"\\n\";\n}\n\n\u002F\u002F even easier with structured bindings (C++17)\nfor (auto& [key, value] : o.items()) {\n  std::cout \u003C\u003C key \u003C\u003C \" : \" \u003C\u003C value \u003C\u003C \"\\n\";\n}\n\n\u002F\u002F find an entry\nif (o.contains(\"foo\")) {\n  \u002F\u002F there is an entry with key \"foo\"\n}\n\n\u002F\u002F or via find and an iterator\nif (o.find(\"foo\") != o.end()) {\n  \u002F\u002F there is an entry with key \"foo\"\n}\n\n\u002F\u002F or simpler using count()\nint foo_present = o.count(\"foo\"); \u002F\u002F 1\nint fob_present = o.count(\"fob\"); \u002F\u002F 0\n\n\u002F\u002F delete an entry\no.erase(\"foo\");\n```\n\n### Conversion from STL containers\n\nAny sequence container (`std::array`, `std::vector`, `std::deque`, `std::forward_list`, `std::list`) whose values can be used to construct JSON values (e.g., integers, floating point numbers, Booleans, string types, or again STL containers described in this section) can be used to create a JSON array. The same holds for similar associative containers (`std::set`, `std::multiset`, `std::unordered_set`, `std::unordered_multiset`), but in these cases the order of the elements of the array depends on how the elements are ordered in the respective STL container.\n\n```cpp\nstd::vector\u003Cint> c_vector {1, 2, 3, 4};\njson j_vec(c_vector);\n\u002F\u002F [1, 2, 3, 4]\n\nstd::deque\u003Cdouble> c_deque {1.2, 2.3, 3.4, 5.6};\njson j_deque(c_deque);\n\u002F\u002F [1.2, 2.3, 3.4, 5.6]\n\nstd::list\u003Cbool> c_list {true, true, false, true};\njson j_list(c_list);\n\u002F\u002F [true, true, false, true]\n\nstd::forward_list\u003Cint64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};\njson j_flist(c_flist);\n\u002F\u002F [12345678909876, 23456789098765, 34567890987654, 45678909876543]\n\nstd::array\u003Cunsigned long, 4> c_array {{1, 2, 3, 4}};\njson j_array(c_array);\n\u002F\u002F [1, 2, 3, 4]\n\nstd::set\u003Cstd::string> c_set {\"one\", \"two\", \"three\", \"four\", \"one\"};\njson j_set(c_set); \u002F\u002F only one entry for \"one\" is used\n\u002F\u002F [\"four\", \"one\", \"three\", \"two\"]\n\nstd::unordered_set\u003Cstd::string> c_uset {\"one\", \"two\", \"three\", \"four\", \"one\"};\njson j_uset(c_uset); \u002F\u002F only one entry for \"one\" is used\n\u002F\u002F maybe [\"two\", \"three\", \"four\", \"one\"]\n\nstd::multiset\u003Cstd::string> c_mset {\"one\", \"two\", \"one\", \"four\"};\njson j_mset(c_mset); \u002F\u002F both entries for \"one\" are used\n\u002F\u002F maybe [\"one\", \"two\", \"one\", \"four\"]\n\nstd::unordered_multiset\u003Cstd::string> c_umset {\"one\", \"two\", \"one\", \"four\"};\njson j_umset(c_umset); \u002F\u002F both entries for \"one\" are used\n\u002F\u002F maybe [\"one\", \"two\", \"one\", \"four\"]\n```\n\nLikewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON values (see examples above) can be used to create a JSON object. Note that in case of multimaps, only one key is used in the JSON object and the value depends on the internal order of the STL container.\n\n```cpp\nstd::map\u003Cstd::string, int> c_map { {\"one\", 1}, {\"two\", 2}, {\"three\", 3} };\njson j_map(c_map);\n\u002F\u002F {\"one\": 1, \"three\": 3, \"two\": 2 }\n\nstd::unordered_map\u003Cconst char*, double> c_umap { {\"one\", 1.2}, {\"two\", 2.3}, {\"three\", 3.4} };\njson j_umap(c_umap);\n\u002F\u002F {\"one\": 1.2, \"two\": 2.3, \"three\": 3.4}\n\nstd::multimap\u003Cstd::string, bool> c_mmap { {\"one\", true}, {\"two\", true}, {\"three\", false}, {\"three\", true} };\njson j_mmap(c_mmap); \u002F\u002F only one entry for key \"three\" is used\n\u002F\u002F maybe {\"one\": true, \"two\": true, \"three\": true}\n\nstd::unordered_multimap\u003Cstd::string, bool> c_ummap { {\"one\", true}, {\"two\", true}, {\"three\", false}, {\"three\", true} };\njson j_ummap(c_ummap); \u002F\u002F only one entry for key \"three\" is used\n\u002F\u002F maybe {\"one\": true, \"two\": true, \"three\": true}\n```\n\n### JSON Pointer and JSON Patch\n\nThe library supports **JSON Pointer** ([RFC 6901](https:\u002F\u002Ftools.ietf.org\u002Fhtml\u002Frfc6901)) as an alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https:\u002F\u002Ftools.ietf.org\u002Fhtml\u002Frfc6902)) allows describing differences between two JSON values -- effectively allowing patch and diff operations known from Unix.\n\n```cpp\n\u002F\u002F a JSON value\njson j_original = R\"({\n  \"baz\": [\"one\", \"two\", \"three\"],\n  \"foo\": \"bar\"\n})\"_json;\n\n\u002F\u002F access members with a JSON pointer (RFC 6901)\nj_original[\"\u002Fbaz\u002F1\"_json_pointer];\n\u002F\u002F \"two\"\n\n\u002F\u002F a JSON patch (RFC 6902)\njson j_patch = R\"([\n  { \"op\": \"replace\", \"path\": \"\u002Fbaz\", \"value\": \"boo\" },\n  { \"op\": \"add\", \"path\": \"\u002Fhello\", \"value\": [\"world\"] },\n  { \"op\": \"remove\", \"path\": \"\u002Ffoo\"}\n])\"_json;\n\n\u002F\u002F apply the patch\njson j_result = j_original.patch(j_patch);\n\u002F\u002F {\n\u002F\u002F    \"baz\": \"boo\",\n\u002F\u002F    \"hello\": [\"world\"]\n\u002F\u002F }\n\n\u002F\u002F calculate a JSON patch from two JSON values\njson::diff(j_result, j_original);\n\u002F\u002F [\n\u002F\u002F   { \"op\":\" replace\", \"path\": \"\u002Fbaz\", \"value\": [\"one\", \"two\", \"three\"] },\n\u002F\u002F   { \"op\": \"remove\",\"path\": \"\u002Fhello\" },\n\u002F\u002F   { \"op\": \"add\", \"path\": \"\u002Ffoo\", \"value\": \"bar\" }\n\u002F\u002F ]\n```\n\n### JSON Merge Patch\n\nThe library supports **JSON Merge Patch** ([RFC 7386](https:\u002F\u002Ftools.ietf.org\u002Fhtml\u002Frfc7386)) as a patch format. Instead of using JSON Pointer (see above) to specify values to be manipulated, it describes the changes using a syntax that closely mimics the document being modified.\n\n```cpp\n\u002F\u002F a JSON value\njson j_document = R\"({\n  \"a\": \"b\",\n  \"c\": {\n    \"d\": \"e\",\n    \"f\": \"g\"\n  }\n})\"_json;\n\n\u002F\u002F a patch\njson j_patch = R\"({\n  \"a\":\"z\",\n  \"c\": {\n    \"f\": null\n  }\n})\"_json;\n\n\u002F\u002F apply the patch\nj_document.merge_patch(j_patch);\n\u002F\u002F {\n\u002F\u002F  \"a\": \"z\",\n\u002F\u002F  \"c\": {\n\u002F\u002F    \"d\": \"e\"\n\u002F\u002F  }\n\u002F\u002F }\n```\n\n### Implicit conversions\n\nSupported types can be implicitly converted to JSON values.\n\nIt is recommended to **NOT USE** implicit conversions **FROM** a JSON value.\nYou can find more details about this recommendation [here](https:\u002F\u002Fwww.github.com\u002Fnlohmann\u002Fjson\u002Fissues\u002F958).\nYou can switch off implicit conversions by defining `JSON_USE_IMPLICIT_CONVERSIONS` to `0` before including the `json.hpp` header. When using CMake, you can also achieve this by setting the option `JSON_ImplicitConversions` to `OFF`.\n\n```cpp\n\u002F\u002F strings\nstd::string s1 = \"Hello, world!\";\njson js = s1;\nauto s2 = js.get\u003Cstd::string>();\n\u002F\u002F NOT RECOMMENDED\nstd::string s3 = js;\nstd::string s4;\ns4 = js;\n\n\u002F\u002F Booleans\nbool b1 = true;\njson jb = b1;\nauto b2 = jb.get\u003Cbool>();\n\u002F\u002F NOT RECOMMENDED\nbool b3 = jb;\nbool b4;\nb4 = jb;\n\n\u002F\u002F numbers\nint i = 42;\njson jn = i;\nauto f = jn.get\u003Cdouble>();\n\u002F\u002F NOT RECOMMENDED\ndouble f2 = jb;\ndouble f3;\nf3 = jb;\n\n\u002F\u002F etc.\n```\n\nNote that `char` types are not automatically converted to JSON strings, but to integer numbers. A conversion to a string must be specified explicitly:\n\n```cpp\nchar ch = 'A';                       \u002F\u002F ASCII value 65\njson j_default = ch;                 \u002F\u002F stores integer number 65\njson j_string = std::string(1, ch);  \u002F\u002F stores string \"A\"\n```\n\n### Arbitrary types conversions\n\nEvery type can be serialized in JSON, not just STL containers and scalar types. Usually, you would do something along those lines:\n\n```cpp\nnamespace ns {\n    \u002F\u002F a simple struct to model a person\n    struct person {\n        std::string name;\n        std::string address;\n        int age;\n    };\n}\n\nns::person p = {\"Ned Flanders\", \"744 Evergreen Terrace\", 60};\n\n\u002F\u002F convert to JSON: copy each value into the JSON object\njson j;\nj[\"name\"] = p.name;\nj[\"address\"] = p.address;\nj[\"age\"] = p.age;\n\n\u002F\u002F ...\n\n\u002F\u002F convert from JSON: copy each value from the JSON object\nns::person p {\n    j[\"name\"].get\u003Cstd::string>(),\n    j[\"address\"].get\u003Cstd::string>(),\n    j[\"age\"].get\u003Cint>()\n};\n```\n\nIt works, but that's quite a lot of boilerplate... Fortunately, there's a better way:\n\n```cpp\n\u002F\u002F create a person\nns::person p {\"Ned Flanders\", \"744 Evergreen Terrace\", 60};\n\n\u002F\u002F conversion: person -> json\njson j = p;\n\nstd::cout \u003C\u003C j \u003C\u003C std::endl;\n\u002F\u002F {\"address\":\"744 Evergreen Terrace\",\"age\":60,\"name\":\"Ned Flanders\"}\n\n\u002F\u002F conversion: json -> person\nauto p2 = j.get\u003Cns::person>();\n\n\u002F\u002F that's it\nassert(p == p2);\n```\n\n#### Basic usage\n\nTo make this work with one of your types, you only need to provide two functions:\n\n```cpp\nusing json = nlohmann::json;\n\nnamespace ns {\n    void to_json(json& j, const person& p) {\n        j = json{{\"name\", p.name}, {\"address\", p.address}, {\"age\", p.age}};\n    }\n\n    void from_json(const json& j, person& p) {\n        j.at(\"name\").get_to(p.name);\n        j.at(\"address\").get_to(p.address);\n        j.at(\"age\").get_to(p.age);\n    }\n} \u002F\u002F namespace ns\n```\n\nThat's all! When calling the `json` constructor with your type, your custom `to_json` method will be automatically called.\nLikewise, when calling `get\u003Cyour_type>()` or `get_to(your_type&)`, the `from_json` method will be called.\n\nSome important things:\n\n- Those methods **MUST** be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined).\n- Those methods **MUST** be available (e.g., proper headers must be included) everywhere you use these conversions. Look at [issue 1108](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues\u002F1108) for errors that may occur otherwise.\n- When using `get\u003Cyour_type>()`, `your_type` **MUST** be [DefaultConstructible](https:\u002F\u002Fen.cppreference.com\u002Fw\u002Fcpp\u002Fnamed_req\u002FDefaultConstructible). (There is a way to bypass this requirement described later.)\n- In function `from_json`, use function [`at()`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fbasic_json\u002Fat\u002F) to access the object values rather than `operator[]`. In case a key does not exist, `at` throws an exception that you can handle, whereas `operator[]` exhibits undefined behavior.\n- You do not need to add serializers or deserializers for STL types like `std::vector`: the library already implements these.\n\n#### Simplify your life with macros\n\nIf you just want to serialize\u002Fdeserialize some structs, the `to_json`\u002F`from_json` functions can be a lot of boilerplate. There are [**several macros**](https:\u002F\u002Fjson.nlohmann.me\u002Ffeatures\u002Farbitrary_types\u002F#simplify-your-life-with-macros) to make your life easier as long as you (1) want to use a JSON object as serialization and (2) want to use the member variable names as object keys in that object.\n\nWhich macro to choose depends on whether private member variables need to be accessed, a deserialization is needed, missing values should yield an error or should be replaced by default values, and if derived classes are used. See [this overview to choose the right one for your use case](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fmacros\u002F#serializationdeserialization-macros).\n\n##### Example usage of macros\n\nThe `to_json`\u002F`from_json` functions for the `person` struct above can be created with [`NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fmacros\u002Fnlohmann_define_type_non_intrusive\u002F). In all macros, the first parameter is the name of the class\u002Fstruct, and all remaining parameters name the members.\n\n```cpp\nnamespace ns {\n    NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person, name, address, age)\n}\n```\n\nHere is another example with private members, where [`NLOHMANN_DEFINE_TYPE_INTRUSIVE`](https:\u002F\u002Fjson.nlohmann.me\u002Fapi\u002Fmacros\u002Fnlohmann_define_type_intrusive\u002F) is needed:\n\n```cpp\nnamespace ns {\n    class address {\n      private:\n        std::string street;\n        int housenumber;\n        int postcode;\n  \n      public:\n        NLOHMANN_DEFINE_TYPE_INTRUSIVE(address, street, housenumber, postcode)\n    };\n}\n```\n\n#### How do I convert third-party types?\n\nThis requires a bit more advanced technique. But first, let's see how this conversion mechanism works:\n\nThe library uses **JSON Serializers** to convert types to JSON.\nThe default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](https:\u002F\u002Fen.cppreference.com\u002Fw\u002Fcpp\u002Flanguage\u002Fadl)).\n\nIt is implemented like this (simplified):\n\n```cpp\ntemplate \u003Ctypename T>\nstruct adl_serializer {\n    static void to_json(json& j, const T& value) {\n        \u002F\u002F calls the \"to_json\" method in T's namespace\n    }\n\n    static void from_json(const json& j, T& value) {\n        \u002F\u002F same thing, but with the \"from_json\" method\n    }\n};\n```\n\nThis serializer works fine when you have control over the type's namespace. However, what about `boost::optional` or `std::filesystem::path` (C++17)? Hijacking the `boost` namespace is pretty bad, and it's illegal to add something other than template specializations to `std`...\n\nTo solve this, you need to add a specialization of `adl_serializer` to the `nlohmann` namespace, here's an example:\n\n```cpp\n\u002F\u002F partial specialization (full specialization works too)\nnamespace nlohmann {\n    template \u003Ctypename T>\n    struct adl_serializer\u003Cboost::optional\u003CT>> {\n        static void to_json(json& j, const boost::optional\u003CT>& opt) {\n            if (opt == boost::none) {\n                j = nullptr;\n            } else {\n              j = *opt; \u002F\u002F this will call adl_serializer\u003CT>::to_json which will\n                        \u002F\u002F find the free function to_json in T's namespace!\n            }\n        }\n\n        static void from_json(const json& j, boost::optional\u003CT>& opt) {\n            if (j.is_null()) {\n                opt = boost::none;\n            } else {\n                opt = j.get\u003CT>(); \u002F\u002F same as above, but with\n                                  \u002F\u002F adl_serializer\u003CT>::from_json\n            }\n        }\n    };\n}\n```\n\n#### How can I use `get()` for non-default constructible\u002Fnon-copyable types?\n\nThere is a way if your type is [MoveConstructible](https:\u002F\u002Fen.cppreference.com\u002Fw\u002Fcpp\u002Fnamed_req\u002FMoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload:\n\n```cpp\nstruct move_only_type {\n    move_only_type() = delete;\n    move_only_type(int ii): i(ii) {}\n    move_only_type(const move_only_type&) = delete;\n    move_only_type(move_only_type&&) = default;\n\n    int i;\n};\n\nnamespace nlohmann {\n    template \u003C>\n    struct adl_serializer\u003Cmove_only_type> {\n        \u002F\u002F note: the return type is no longer 'void', and the method only takes\n        \u002F\u002F one argument\n        static move_only_type from_json(const json& j) {\n            return {j.get\u003Cint>()};\n        }\n\n        \u002F\u002F Here's the catch! You must provide a to_json method! Otherwise, you\n        \u002F\u002F will not be able to convert move_only_type to json, since you fully\n        \u002F\u002F specialized adl_serializer on that type\n        static void to_json(json& j, move_only_type t) {\n            j = t.i;\n        }\n    };\n}\n```\n\n#### Can I write my own serializer? (Advanced use)\n\nYes. You might want to take a look at [`unit-udt.cpp`](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fblob\u002Fdevelop\u002Ftests\u002Fsrc\u002Funit-udt.cpp) in the test suite, to see a few examples.\n\nIf you write your own serializer, you'll need to do a few things:\n\n- use a different `basic_json` alias than `nlohmann::json` (the last template parameter of `basic_json` is the `JSONSerializer`)\n- use your `basic_json` alias (or a template parameter) in all your `to_json`\u002F`from_json` methods\n- use `nlohmann::to_json` and `nlohmann::from_json` when you need ADL\n\nHere is an example, without simplifications, that only accepts types with a size \u003C= 32, and uses ADL.\n\n```cpp\n\u002F\u002F You should use void as a second template argument\n\u002F\u002F if you don't need compile-time checks on T\ntemplate\u003Ctypename T, typename SFINAE = typename std::enable_if\u003Csizeof(T) \u003C= 32>::type>\nstruct less_than_32_serializer {\n    template \u003Ctypename BasicJsonType>\n    static void to_json(BasicJsonType& j, T value) {\n        \u002F\u002F we want to use ADL, and call the correct to_json overload\n        using nlohmann::to_json; \u002F\u002F this method is called by adl_serializer,\n                                 \u002F\u002F this is where the magic happens\n        to_json(j, value);\n    }\n\n    template \u003Ctypename BasicJsonType>\n    static void from_json(const BasicJsonType& j, T& value) {\n        \u002F\u002F same thing here\n        using nlohmann::from_json;\n        from_json(j, value);\n    }\n};\n```\n\nBe **very** careful when reimplementing your serializer, you can stack overflow if you don't pay attention:\n\n```cpp\ntemplate \u003Ctypename T, void>\nstruct bad_serializer\n{\n    template \u003Ctypename BasicJsonType>\n    static void to_json(BasicJsonType& j, const T& value) {\n      \u002F\u002F this calls BasicJsonType::json_serializer\u003CT>::to_json(j, value)\n      \u002F\u002F if BasicJsonType::json_serializer == bad_serializer ... oops!\n      j = value;\n    }\n\n    template \u003Ctypename BasicJsonType>\n    static void to_json(const BasicJsonType& j, T& value) {\n      \u002F\u002F this calls BasicJsonType::json_serializer\u003CT>::from_json(j, value)\n      \u002F\u002F if BasicJsonType::json_serializer == bad_serializer ... oops!\n      value = j.get\u003CT>(); \u002F\u002F oops!\n    }\n};\n```\n\n### Specializing enum conversion\n\nBy default, enum values are serialized to JSON as integers. In some cases, this could result in undesired behavior. If an enum is modified or re-ordered after data has been serialized to JSON, the later deserialized JSON data may be undefined or a different enum value than was originally intended.\n\nIt is possible to more precisely specify how a given enum is mapped to and from JSON as shown below:\n\n```cpp\n\u002F\u002F example enum type declaration\nenum TaskState {\n    TS_STOPPED,\n    TS_RUNNING,\n    TS_COMPLETED,\n    TS_INVALID=-1,\n};\n\n\u002F\u002F map TaskState values to JSON as strings\nNLOHMANN_JSON_SERIALIZE_ENUM( TaskState, {\n    {TS_INVALID, nullptr},\n    {TS_STOPPED, \"stopped\"},\n    {TS_RUNNING, \"running\"},\n    {TS_COMPLETED, \"completed\"},\n})\n```\n\nThe `NLOHMANN_JSON_SERIALIZE_ENUM()` macro declares a set of `to_json()` \u002F `from_json()` functions for type `TaskState` while avoiding repetition and boilerplate serialization code.\n\n**Usage:**\n\n```cpp\n\u002F\u002F enum to JSON as string\njson j = TS_STOPPED;\nassert(j == \"stopped\");\n\n\u002F\u002F json string to enum\njson j3 = \"running\";\nassert(j3.get\u003CTaskState>() == TS_RUNNING);\n\n\u002F\u002F undefined json value to enum (where the first map entry above is the default)\njson jPi = 3.14;\nassert(jPi.get\u003CTaskState>() == TS_INVALID);\n```\n\nJust as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,\n\n- `NLOHMANN_JSON_SERIALIZE_ENUM()` MUST be declared in your enum type's namespace (which can be the global namespace), or the library will not be able to locate it, and it will default to integer serialization.\n- It MUST be available (e.g., proper headers must be included) everywhere you use the conversions.\n\nOther Important points:\n\n- When using `get\u003CENUM_TYPE>()`, undefined JSON values will default to the first pair specified in your map. Select this default pair carefully.\n- If an enum or JSON value is specified more than once in your map, the first matching occurrence from the top of the map will be returned when converting to or from JSON.\n\n### Binary formats (BSON, CBOR, MessagePack, UBJSON, and BJData)\n\nThough JSON is a ubiquitous data format, it is not a very compact format suitable for data exchange, for instance over a network. Hence, the library supports [BSON](https:\u002F\u002Fbsonspec.org) (Binary JSON), [CBOR](https:\u002F\u002Fcbor.io) (Concise Binary Object Representation), [MessagePack](https:\u002F\u002Fmsgpack.org), [UBJSON](https:\u002F\u002Fubjson.org) (Universal Binary JSON Specification) and [BJData](https:\u002F\u002Fneurojson.org\u002Fbjdata) (Binary JData) to efficiently encode JSON values to byte vectors and to decode such vectors.\n\n```cpp\n\u002F\u002F create a JSON value\njson j = R\"({\"compact\": true, \"schema\": 0})\"_json;\n\n\u002F\u002F serialize to BSON\nstd::vector\u003Cstd::uint8_t> v_bson = json::to_bson(j);\n\n\u002F\u002F 0x1B, 0x00, 0x00, 0x00, 0x08, 0x63, 0x6F, 0x6D, 0x70, 0x61, 0x63, 0x74, 0x00, 0x01, 0x10, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n\n\u002F\u002F roundtrip\njson j_from_bson = json::from_bson(v_bson);\n\n\u002F\u002F serialize to CBOR\nstd::vector\u003Cstd::uint8_t> v_cbor = json::to_cbor(j);\n\n\u002F\u002F 0xA2, 0x67, 0x63, 0x6F, 0x6D, 0x70, 0x61, 0x63, 0x74, 0xF5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x00\n\n\u002F\u002F roundtrip\njson j_from_cbor = json::from_cbor(v_cbor);\n\n\u002F\u002F serialize to MessagePack\nstd::vector\u003Cstd::uint8_t> v_msgpack = json::to_msgpack(j);\n\n\u002F\u002F 0x82, 0xA7, 0x63, 0x6F, 0x6D, 0x70, 0x61, 0x63, 0x74, 0xC3, 0xA6, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x00\n\n\u002F\u002F roundtrip\njson j_from_msgpack = json::from_msgpack(v_msgpack);\n\n\u002F\u002F serialize to UBJSON\nstd::vector\u003Cstd::uint8_t> v_ubjson = json::to_ubjson(j);\n\n\u002F\u002F 0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61, 0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D\n\n\u002F\u002F roundtrip\njson j_from_ubjson = json::from_ubjson(v_ubjson);\n```\n\nThe library also supports binary types from BSON, CBOR (byte strings), and MessagePack (bin, ext, fixext). They are stored by default as `std::vector\u003Cstd::uint8_t>` to be processed outside the library.\n\n```cpp\n\u002F\u002F CBOR byte string with payload 0xCAFE\nstd::vector\u003Cstd::uint8_t> v = {0x42, 0xCA, 0xFE};\n\n\u002F\u002F read value\njson j = json::from_cbor(v);\n\n\u002F\u002F the JSON value has type binary\nj.is_binary(); \u002F\u002F true\n\n\u002F\u002F get reference to stored binary value\nauto& binary = j.get_binary();\n\n\u002F\u002F the binary value has no subtype (CBOR has no binary subtypes)\nbinary.has_subtype(); \u002F\u002F false\n\n\u002F\u002F access std::vector\u003Cstd::uint8_t> member functions\nbinary.size(); \u002F\u002F 2\nbinary[0]; \u002F\u002F 0xCA\nbinary[1]; \u002F\u002F 0xFE\n\n\u002F\u002F set subtype to 0x10\nbinary.set_subtype(0x10);\n\n\u002F\u002F serialize to MessagePack\nauto cbor = json::to_msgpack(j); \u002F\u002F 0xD5 (fixext2), 0x10, 0xCA, 0xFE\n```\n\n## Customers\n\nThe library is used in multiple projects, applications, operating systems, etc. The list below is not exhaustive, but the result of an internet search. If you know further customers of the library, please let me know, see [contact](#contact).\n\n[![logos of customers using the library](docs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fcustomers.png)](https:\u002F\u002Fjson.nlohmann.me\u002Fhome\u002Fcustomers\u002F)\n\n## Supported compilers\n\nThough it's 2026 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:\n\n- GCC 4.8 - 14.2 (and possibly later)\n- Clang 3.4 - 21.0 (and possibly later)\n- Apple Clang 9.1 - 16.0 (and possibly later)\n- Intel C++ Compiler 17.0.2 (and possibly later)\n- Nvidia CUDA Compiler 11.0.221 (and possibly later)\n- Microsoft Visual C++ 2015 \u002F Build Tools 14.0.25123.0 (and possibly later)\n- Microsoft Visual C++ 2017 \u002F Build Tools 15.5.180.51428 (and possibly later)\n- Microsoft Visual C++ 2019 \u002F Build Tools 16.3.1+1def00d3d (and possibly later)\n- Microsoft Visual C++ 2022 \u002F Build Tools 19.30.30709.0 (and possibly later)\n\nI would be happy to learn about other compilers\u002Fversions.\n\nPlease note:\n\n- GCC 4.8 has a bug [57824](https:\u002F\u002Fgcc.gnu.org\u002Fbugzilla\u002Fshow_bug.cgi?id=57824): multiline raw strings cannot be the arguments to macros. Don't use multiline raw strings directly in macros with this compiler.\n- Android defaults to using very old compilers and C++ libraries. To fix this, add the following to your `Application.mk`. This will switch to the LLVM C++ library, the Clang compiler, and enable C++11 and other features disabled by default.\n\n    ```makefile\n    APP_STL := c++_shared\n    NDK_TOOLCHAIN_VERSION := clang3.6\n    APP_CPPFLAGS += -frtti -fexceptions\n    ```\n\n    The code compiles successfully with [Android NDK](https:\u002F\u002Fdeveloper.android.com\u002Fndk\u002Findex.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https:\u002F\u002Fwww.crystax.net\u002Fen\u002Fandroid\u002Fndk) version 10.\n\n- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod` or `strtof`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment.  For MinGW, please refer to [this site](https:\u002F\u002Ftehsausage.com\u002Fmingw-to-string) and [this discussion](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues\u002F136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues\u002F219).\n\n- Unsupported versions of GCC and Clang are rejected by `#error` directives. This can be switched off by defining `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`. Note that you can expect no support in this case.\n\nSee the page [quality assurance](https:\u002F\u002Fjson.nlohmann.me\u002Fcommunity\u002Fquality_assurance) on the compilers used to check the library in the CI.\n\n## Integration\n\n[`json.hpp`](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fblob\u002Fdevelop\u002Fsingle_include\u002Fnlohmann\u002Fjson.hpp) is the single required file in `single_include\u002Fnlohmann` or [released here](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Freleases). You need to add\n\n```cpp\n#include \u003Cnlohmann\u002Fjson.hpp>\n\n\u002F\u002F for convenience\nusing json = nlohmann::json;\n```\n\nto the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang).\n\nYou can further use file [`include\u002Fnlohmann\u002Fjson_fwd.hpp`](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fblob\u002Fdevelop\u002Finclude\u002Fnlohmann\u002Fjson_fwd.hpp) for forward-declarations. The installation of `json_fwd.hpp` (as part of cmake's install step) can be achieved by setting `-DJSON_MultipleHeaders=ON`.\n\n### CMake\n\nYou can also use the `nlohmann_json::nlohmann_json` interface target in CMake.  This target populates the appropriate usage requirements for `INTERFACE_INCLUDE_DIRECTORIES` to point to the appropriate include directories and `INTERFACE_COMPILE_FEATURES` for the necessary C++11 flags.\n\n#### External\n\nTo use this library from a CMake project, you can locate it directly with `find_package()` and use the namespaced imported target from the generated package configuration:\n\n```cmake\n# CMakeLists.txt\nfind_package(nlohmann_json 3.12.0 REQUIRED)\n...\nadd_library(foo ...)\n...\ntarget_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)\n```\n\nThe package configuration file, `nlohmann_jsonConfig.cmake`, can be used either from an install tree or directly out of the build tree.\n\n#### Embedded\n\nTo embed the library directly into an existing CMake project, place the entire source tree in a subdirectory and call `add_subdirectory()` in your `CMakeLists.txt` file:\n\n```cmake\n# Typically you don't care so much for a third party library's tests to be\n# run from your own project's code.\nset(JSON_BuildTests OFF CACHE INTERNAL \"\")\n\n# If you only include this third party in PRIVATE source files, you do not\n# need to install it when your main project gets installed.\n# set(JSON_Install OFF CACHE INTERNAL \"\")\n\n# Don't use include(nlohmann_json\u002FCMakeLists.txt) since that carries with it\n# unintended consequences that will break the build.  It's generally\n# discouraged (although not necessarily well documented as such) to use\n# include(...) for pulling in other CMake projects anyways.\nadd_subdirectory(nlohmann_json)\n...\nadd_library(foo ...)\n...\ntarget_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)\n```\n\n##### Embedded (FetchContent)\n\nSince CMake v3.11,\n[FetchContent](https:\u002F\u002Fcmake.org\u002Fcmake\u002Fhelp\u002Fv3.11\u002Fmodule\u002FFetchContent.html) can\nbe used to automatically download a release as a dependency at configure time.\n\nExample:\n\n```cmake\ninclude(FetchContent)\n\nFetchContent_Declare(json URL https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Freleases\u002Fdownload\u002Fv3.12.0\u002Fjson.tar.xz)\nFetchContent_MakeAvailable(json)\n\ntarget_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)\n```\n\n**Note**: It is recommended to use the URL approach described above, which is supported as of version 3.10.0. See\n\u003Chttps:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fcmake\u002F#fetchcontent> for more information.\n\n#### Supporting Both\n\nTo allow your project to support either an externally supplied or an embedded JSON library, you can use a pattern akin to the following:\n\n``` cmake\n# Top level CMakeLists.txt\nproject(FOO)\n...\noption(FOO_USE_EXTERNAL_JSON \"Use an external JSON library\" OFF)\n...\nadd_subdirectory(thirdparty)\n...\nadd_library(foo ...)\n...\n# Note that the namespaced target will always be available regardless of the\n# import method\ntarget_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)\n```\n\n```cmake\n# thirdparty\u002FCMakeLists.txt\n...\nif(FOO_USE_EXTERNAL_JSON)\n  find_package(nlohmann_json 3.12.0 REQUIRED)\nelse()\n  set(JSON_BuildTests OFF CACHE INTERNAL \"\")\n  add_subdirectory(nlohmann_json)\nendif()\n...\n```\n\n`thirdparty\u002Fnlohmann_json` is then a complete copy of this source tree.\n\n### Package Managers\n\nUse your favorite [**package manager**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F) to use the library.\n\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fhomebrew.svg\" height=\"20\">&nbsp;[**Homebrew**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#homebrew) `nlohmann-json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fmeson.svg\" height=\"20\">&nbsp;[**Meson**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#meson) `nlohmann_json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fbazel.svg\" height=\"20\">&nbsp;[**Bazel**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#bazel) `nlohmann_json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fconan.svg\" height=\"20\">&nbsp;[**Conan**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#conan) `nlohmann_json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fspack.svg\" height=\"20\">&nbsp;[**Spack**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#spack) `nlohmann-json`\n- [**Hunter**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#hunter) `nlohmann_json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fvcpkg.png\" height=\"20\">&nbsp;[**vcpkg**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#vcpkg) `nlohmann-json`\n- [**cget**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#cget) `nlohmann\u002Fjson`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fswift.svg\" height=\"20\">&nbsp;[**Swift Package Manager**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#swift-package-manager) `nlohmann\u002Fjson`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fnuget.svg\" height=\"20\">&nbsp;[**Nuget**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#nuget) `nlohmann.json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fconda.svg\" height=\"20\">&nbsp;[**Conda**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#conda) `nlohmann_json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fmacports.svg\" height=\"20\">&nbsp;[**MacPorts**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#macports) `nlohmann-json`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002FCPM.png\" height=\"20\">&nbsp;[**cpm.cmake**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#cpmcmake) `gh:nlohmann\u002Fjson`\n- \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Frefs\u002Fheads\u002Fdevelop\u002Fdocs\u002Fmkdocs\u002Fdocs\u002Fimages\u002Fpackage_managers\u002Fxmake.svg\" height=\"20\">&nbsp;[**xmake**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F#xmake) `nlohmann_json`\n\nThe library is part of many package managers. See the [**documentation**](https:\u002F\u002Fjson.nlohmann.me\u002Fintegration\u002Fpackage_managers\u002F) for detailed descriptions and examples.\n\n### Pkg-config\n\nIf you are using bare Makefiles, you can use `pkg-config` to generate the include flags that point to where the library is installed:\n\n```sh\npkg-config nlohmann_json --cflags\n```\n\n## License\n\n\u003Cimg align=\"right\" src=\"https:\u002F\u002F149753425.v2.pressablecdn.com\u002Fwp-content\u002Fuploads\u002F2009\u002F06\u002FOSIApproved_100X125.png\" alt=\"OSI approved license\">\n\nThe class is licensed under the [MIT License](https:\u002F\u002Fopensource.org\u002Flicenses\u002FMIT):\n\nCopyright &copy; 2013-2026 [Niels Lohmann](https:\u002F\u002Fnlohmann.me)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and\u002For sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n* * *\n\n- The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed under the [MIT License](https:\u002F\u002Fopensource.org\u002Flicenses\u002FMIT) (see above). Copyright &copy; 2008-2009 [Björn Hoehrmann](https:\u002F\u002Fbjoern.hoehrmann.de\u002F) \u003Cbjoern@hoehrmann.de>\n- The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](https:\u002F\u002Fopensource.org\u002Flicenses\u002FMIT) (see above). Copyright &copy; 2009 [Florian Loitsch](https:\u002F\u002Fflorian.loitsch.com\u002F)\n- The class contains a copy of [Hedley](https:\u002F\u002Fnemequ.github.io\u002Fhedley\u002F) from Evan Nemerson which is licensed as [CC0-1.0](https:\u002F\u002Fcreativecommons.org\u002Fpublicdomain\u002Fzero\u002F1.0\u002F).\n- The class contains parts of [Google Abseil](https:\u002F\u002Fgithub.com\u002Fabseil\u002Fabseil-cpp) which is licensed under the [Apache 2.0 License](https:\u002F\u002Fopensource.org\u002Flicenses\u002FApache-2.0).\n\n\u003Cimg align=\"right\" src=\"https:\u002F\u002Fgit.fsfe.org\u002Freuse\u002Freuse-ci\u002Fraw\u002Fbranch\u002Fmaster\u002Freuse-horizontal.png\" alt=\"REUSE Software\">\n\nThe library is compliant to version 3.3 of the [**REUSE specification**](https:\u002F\u002Freuse.software):\n\n- Every source file contains an SPDX copyright header.\n- The full text of all licenses used in the repository can be found in the `LICENSES` folder.\n- File `.reuse\u002Fdep5` contains an overview of all files' copyrights and licenses.\n- Run `pipx run reuse lint` to verify the project's REUSE compliance and `pipx run reuse spdx` to generate a SPDX SBOM.\n\n## Contact\n\nIf you have questions regarding the library, I would like to invite you to [open an issue at GitHub](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues\u002Fnew\u002Fchoose). Please describe your request, problem, or question as detailed as possible, and also mention the version of the library you are using as well as the version of your compiler and operating system. Opening an issue at GitHub allows other users and contributors to this library to collaborate. For instance, I have little experience with MSVC, and most issues in this regard have been solved by a growing community. If you have a look at the [closed issues](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fissues?q=is%3Aissue+is%3Aclosed), you will see that we react quite timely in most cases.\n\nOnly if your request would contain confidential information, please [send me an email](mailto:mail@nlohmann.me). For encrypted messages, please use [this key](https:\u002F\u002Fkeybase.io\u002Fnlohmann\u002Fpgp_keys.asc).\n\n## Security\n\n[Commits by Niels Lohmann](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Fcommits) and [releases](https:\u002F\u002Fgithub.com\u002Fnlohmann\u002Fjson\u002Freleases) are signed with this [PGP Key](https:\u002F\u002Fkeybase.io\u002Fnlohmann\u002Fpgp_keys.asc?fingerprint=797167ae41c0a6d9232e48457f3cea63ae251b69).\n\n## Thanks\n\nI deeply appreciate the help of the following people.\n\n\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fnlohmann\u002Fjson\u002Fdevelop\u002Fdocs\u002Favatars.png\" align=\"right\" alt=\"GitHub avatars of the contributors\">\n\n1. [Teemperor](https:\u002F\u002Fgithub.com\u002FTeemperor) implemented CMake support and lcov integration, realized escape and Unicode handling in the string parser, and fixed the JSON serialization.\n2. [elliotgoodrich](https:\u002F\u002Fgithub.com\u002Felliotgoodrich) fixed an issue with double deletion in the iterator classes.\n3. [kirkshoop](https:\u002F\u002Fgithub.com\u002Fkirkshoop) made the iterators of the class composable to other libraries.\n4. [wancw](https:\u002F\u002Fgithub.com\u002Fwanwc) fixed a bug that hindered the class to compile with Clang.\n5. Tomas Åblad found a bug in the iterator implementation.\n6. [Joshua C. Randall](https:\u002F\u002Fgithub.com\u002Fjrandall) fixed a bug in the floating-point serialization.\n7. [Aaron Burghardt](https:\u002F\u002Fgithub.com\u002Faburgh) implemented code to parse streams incrementally. Furthermore, he greatly improved the parser class by allowing the definition of a filter function to discard undesired elements while parsing.\n8. [Daniel Kopeček](https:\u002F\u002Fgithub.com\u002Fdkopecek) fixed a bug in the compilation with GCC 5.0.\n9. [Florian Weber](https:\u002F\u002Fgithub.com\u002FFlorianjw) fixed a bug in and improved the performance of the comparison operators.\n10. [Eric Cornelius](https:\u002F\u002Fgithub.com\u002FEricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping.\n11. [易思龙](https:\u002F\u002Fgithub.com\u002Flikebeta) implemented a conversion from anonymous enums.\n12. [kepkin](https:\u002F\u002Fgithub.com\u002Fkepkin) patiently pushed forward the support for Microsoft Visual Studio.\n13. [gregmarr","nlohmann\u002Fjson 是一个专为现代C++设计的JSON库。该项目提供了一种简单高效的方式来解析、序列化和操作JSON数据，支持包括RFC 6901, RFC 6902, RFC 7049等在内的多种标准，并且完全基于头文件，无需编译即可使用。此外，它还集成了对BSON、CBOR、MessagePack等多种数据格式的支持，使得在不同场景下的数据交换变得更加灵活。适用于需要处理JSON数据的各种C++项目，尤其是在网络通信、配置管理以及数据存储等方面有着广泛的应用价值。",2,"2026-06-11 02:38:55","top_all"]