Json++ is a memory-efficient, dependency-free, lazy C++11 JSON reader and writer.
Table of Contents
- Motivation
- Getting Started
- Design
- Building
- Testing
- Portability
- Documentation
- Planned Features
- Acknowledgments
- Contributor Guidelines
- License
DOM sucks. DOM APIs read the entire document into memory, making DOM useless for large workloads.
SAX sucks. SAX APIs map specific events to specific handlers, requiring conditional branches for each tree in the document, producing tedious amounts of boilerplate.
Iteration rules. Inspired by the TextReader and TextWriter APIs from .NET, Json++ provides iterative access to each node as the document is parsed, simplifying tree-specific parsing with minimal overhead.
Json++ features:
- Low memory overhead
- Tree-like logic
- STL-like iterators, auto-ranges, and STL container adapters
#include <json/reader.hpp>
#include <json/writer.hpp>
#include <iostream>
int main(void)
{
// read document into map
json::StringTextReader reader(" {\"1\":2} \n");
std::unordered_map<int, int> map(reader.object());
// re-create JSON document from map
json::StringTextWriter writer;
writer.write(map);
// write {"1":2} to stdout
std::cout << writer.str() << std::endl;
return 0;
}Simply clone, configure with CMake, and build.
git clone https://github.com/Alexhuszagh/json.git
git submodule update --init
cd json/build
cmake .. -_DBUILD_TESTS=ON # "-DBUILD_FUZZ=ON" for fuzzing with Clang
make -j 5 # "msbuild JSON.sln" for MSVCJson++ has been tested with a variety of JSON files, for compliance and accurate parsing, fully passing the conformance tests and roundtrip tests from Milo Yip's JSON benchmarks.
The core parser has also been extensively fuzzed (see Fuzz Tests), since bugs in JSON parsing can be used as attack vectors against web services.
Json++ has been tested with the following compilers and operating systems:
- 64-bit Linux with Clang 3.8.2
- 64-bit Linux with GCC 5.4.0
- 32/64-bit Windows with MinGW 5.3.0 (MXE, MinGW, and MSYS2) //- 32/64-bit Windows with Visual Studio 14 2015
Coming soon, for now, see the the examples for how to use Json++.
- DOM-style API using the TextReader internally.
- Pretty Printing
- Fast string formatting and extraction (replacing std::to_string and std::stod).
Json++ also uses some code and test files from Niels Lohmann and Milo Yip, from their Json and RapidJson projects. All files in the jsonchecker directory are from Milo Yip's nativejson-benchmark and the remaining sample files come from Niel Lohmann's JSON tests.
All useful pull requests will be merged, provided that they do not add external dependencies and follow these guidelines.
- Preprocessor macros should be used sparingly.
- Code syntax should not depend on the preprocessor.
- Your code must be readable.
MIT, see license.