deploy: a47170346a
This commit is contained in:
1 parent
b36f8a9821
commit
11a863958e
1180 files changed
+14211
-6025
No files matched your search
@@ -1,71 +1,19 @@
|
||||
---
|
||||
template: home.html
|
||||
hide:
|
||||
- toc
|
||||
---
|
||||
|
||||
# JSON for Modern C++
|
||||
|
||||

|
||||
|
||||
JSON for Modern C++ is a header-only C++11 library that turns JSON into a first-class C++ data type, using the operator
|
||||
magic of modern C++ so that creating, reading, and modifying JSON values feels as natural as it does in languages like
|
||||
Python. The whole library is available as a single header, `json.hpp`, with no dependencies, no subproject, and no
|
||||
complex build system to set up; a companion header, `json_fwd.hpp`, provides forward declarations to keep compile times
|
||||
down, `<nlohmann/json_literals.hpp>` holds the user-defined string literals on their own, and
|
||||
`<nlohmann/json_view.hpp>` adds zero-copy views and editable documents. See
|
||||
[header-only integration](integration/index.md) for details. It is heavily unit-tested with 100% code
|
||||
coverage, checked with Valgrind and the Clang Sanitizers for memory leaks, and continuously fuzz-tested by Google
|
||||
OSS-Fuzz.
|
||||
|
||||
## Quick start
|
||||
|
||||
Add the single header to your project and use the library like this:
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// parse a JSON string
|
||||
json j = json::parse(R"({"happy": true, "pi": 3.141})");
|
||||
|
||||
// access and modify values
|
||||
j["name"] = "Niels";
|
||||
j["list"] = {1, 0, 2};
|
||||
|
||||
// read a value into a C++ variable and use it
|
||||
double pi = j["pi"].get<double>();
|
||||
std::cout << "2 * pi = " << 2 * pi << '\n';
|
||||
|
||||
// serialize with an indent of 4 spaces
|
||||
std::cout << j.dump(4) << '\n';
|
||||
}
|
||||
```
|
||||
|
||||
Get the library by copying the single header [`json.hpp`](https://github.com/nlohmann/json/releases) from the
|
||||
releases page into a directory `nlohmann` on your include path, or by installing it with a package manager:
|
||||
|
||||
```sh
|
||||
brew install nlohmann-json # Homebrew
|
||||
vcpkg install nlohmann-json # vcpkg
|
||||
```
|
||||
|
||||
```cmake
|
||||
find_package(nlohmann_json 3.12.0 REQUIRED)
|
||||
target_link_libraries(myproject PRIVATE nlohmann_json::nlohmann_json)
|
||||
```
|
||||
|
||||
See [Integration](integration/index.md) for CMake in detail, all supported package managers (Conan, Meson, Bazel,
|
||||
Conda, and more), and pkg-config.
|
||||
|
||||
## Explore the documentation
|
||||
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- :octicons-rocket-24:{ .lg .middle } __Features__
|
||||
|
||||
---
|
||||
|
||||
Creating, parsing, accessing, and serializing JSON values, JSON Pointer/Patch, binary formats, zero-copy views,
|
||||
and more.
|
||||
Creating, parsing, accessing, and serializing JSON values, converting your own C++ types, JSON Pointer/Patch/Merge
|
||||
Patch, binary formats, zero-copy views, and more.
|
||||
|
||||
[:octicons-arrow-right-24: Features](features/index.md)
|
||||
|
||||
@@ -112,11 +60,5 @@ Conda, and more), and pkg-config.
|
||||
|
||||
</div>
|
||||
|
||||
!!! info "Unreleased changes"
|
||||
|
||||
This documentation is built from the `develop` branch and may describe changes that are not part of a release
|
||||
yet. Their version numbers are followed by an <span class="unreleased-version">unreleased</span> badge; see
|
||||
[Releases](home/releases/index.md) for what shipped in each version.
|
||||
|
||||
The library is licensed under the [MIT License](home/license.md). The source code, issue tracker, and discussions
|
||||
are on [GitHub](https://github.com/nlohmann/json).
|
||||

|
||||

|
||||
Reference in new issue
Block a user