2017-01-12 10:57:34 +01:00
# JsonCpp
2007-06-14 21:01:26 +00:00
2017-04-09 14:14:38 -03:00
[![badge ](https://img.shields.io/badge/conan.io-jsoncpp%2F1.8.0-green.svg?logo=data:image/png;base64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAA1VBMVEUAAABhlctjlstkl8tlmMtlmMxlmcxmmcxnmsxpnMxpnM1qnc1sn85voM91oM11oc1xotB2oc56pNF6pNJ2ptJ8ptJ8ptN9ptN8p9N5qNJ9p9N9p9R8qtOBqdSAqtOAqtR%2BrNSCrNJ/rdWDrNWCsNWCsNaJs9eLs9iRvNuVvdyVv9yXwd2Zwt6axN6dxt%2Bfx%2BChyeGiyuGjyuCjyuGly%2BGlzOKmzOGozuKoz%2BKqz%2BOq0OOv1OWw1OWw1eWx1eWy1uay1%2Baz1%2Baz1%2Bez2Oe02Oe12ee22ujUGwH3AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgBQkREyOxFIh/AAAAiklEQVQI12NgAAMbOwY4sLZ2NtQ1coVKWNvoc/Eq8XDr2wB5Ig62ekza9vaOqpK2TpoMzOxaFtwqZua2Bm4makIM7OzMAjoaCqYuxooSUqJALjs7o4yVpbowvzSUy87KqSwmxQfnsrPISyFzWeWAXCkpMaBVIC4bmCsOdgiUKwh3JojLgAQ4ZCE0AMm2D29tZwe6AAAAAElFTkSuQmCC )](http://www.conan.io/source/jsoncpp/1.8.0/theirix/ci)
2014-07-01 11:56:56 +10:00
[JSON][json-org] is a lightweight data-interchange format. It can represent
numbers, strings, ordered sequences of values, and collections of name/value
pairs.
2007-06-14 21:01:26 +00:00
2014-07-01 11:56:56 +10:00
[json-org]: http://json.org/
2007-06-14 21:01:26 +00:00
2017-01-12 10:57:34 +01:00
JsonCpp is a C++ library that allows manipulating JSON values, including
2014-07-01 11:56:56 +10:00
serialization and deserialization to and from strings. It can also preserve
existing comment in unserialization/serialization steps, making it a convenient
format to store user input files.
2007-06-14 21:01:26 +00:00
2017-01-12 10:57:34 +01:00
## Documentation
[JsonCpp documentation][JsonCpp-documentation] is generated using [Doxygen][].
[JsonCpp-documentation]: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html
[Doxygen]: http://www.doxygen.org
2015-02-12 11:18:23 -06:00
2014-11-03 12:39:01 -06:00
## A note on backward-compatibility
2017-01-12 10:57:34 +01:00
2015-02-12 11:18:23 -06:00
* `1.y.z` is built with C++11.
2015-03-05 21:45:42 -06:00
* `0.y.z` can be used with older compilers.
2015-02-12 11:18:23 -06:00
* Major versions maintain binary-compatibility.
2013-05-08 20:21:11 +00:00
2017-01-12 10:57:34 +01:00
## Contributing to JsonCpp
2019-01-24 09:57:56 -06:00
### Building
Both CMake and Meson tools are capable of generating a variety of build environments for you preferred development environment.
Using cmake or meson you can generate an XCode, Visual Studio, Unix Makefile, Ninja, or other environment that fits your needs.
An example of a common Meson/Ninja environment is described next.
2017-08-27 14:45:02 -05:00
### Building and testing with Meson/Ninja
2019-01-12 12:32:15 -06:00
Thanks to David Seifert (@SoapGentoo), we (the maintainers) now use
[meson ](http://mesonbuild.com/ ) and [ninja ](https://ninja-build.org/ ) to build
for debugging, as well as for continuous integration (see
[`./travis_scripts/meson_builder.sh` ](./travis_scripts/meson_builder.sh ) ). Other systems may work, but minor
things like version strings might break.
2017-04-09 14:14:38 -03:00
2017-08-27 14:45:02 -05:00
First, install both meson (which requires Python3) and ninja.
2017-10-18 00:20:45 -05:00
If you wish to install to a directory other than /usr/local, set an environment variable called DESTDIR with the desired path:
DESTDIR=/path/to/install/dir
2017-04-09 14:14:38 -03:00
2017-08-27 14:45:02 -05:00
Then,
2017-04-09 14:14:38 -03:00
2017-08-27 14:45:02 -05:00
cd jsoncpp/
2017-09-04 21:07:49 +02:00
BUILD_TYPE=debug
#BUILD_TYPE =release
LIB_TYPE=shared
#LIB_TYPE =static
2017-08-27 14:45:02 -05:00
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
2018-06-23 16:34:57 -05:00
#ninja -v -C build-${LIB_TYPE} test # This stopped working on my Mac.
ninja -v -C build-${LIB_TYPE}
2017-09-04 21:07:49 +02:00
cd build-${LIB_TYPE}
2018-06-23 16:34:57 -05:00
meson test --no-rebuild --print-errorlogs
2017-09-04 21:07:49 +02:00
sudo ninja install
2017-04-09 14:14:38 -03:00
2017-08-27 14:45:02 -05:00
### Building and testing with other build systems
See https://github.com/open-source-parsers/jsoncpp/wiki/Building
2014-07-01 12:06:16 +10:00
2017-01-12 10:57:34 +01:00
### Running the tests manually
2014-07-01 13:06:40 +10:00
You need to run tests manually only if you are troubleshooting an issue.
In the instructions below, replace `path/to/jsontest` with the path of the
`jsontest` executable that was compiled on your platform.
cd test
# This will run the Reader/Writer tests
python runjsontests.py path/to/jsontest
2017-04-09 14:14:38 -03:00
2014-07-01 13:06:40 +10:00
# This will run the Reader/Writer tests, using JSONChecker test suite
# (http://www.json.org/JSON_checker/).
# Notes: not all tests pass: JsonCpp is too lenient (for example,
# it allows an integer to start with '0'). The goal is to improve
# strict mode parsing to get all tests to pass.
python runjsontests.py --with-json-checker path/to/jsontest
2017-04-09 14:14:38 -03:00
2014-07-01 13:06:40 +10:00
# This will run the unit tests (mostly Value)
python rununittests.py path/to/test_lib_json
2017-04-09 14:14:38 -03:00
2014-07-01 13:06:40 +10:00
# You can run the tests using valgrind:
python rununittests.py --valgrind path/to/test_lib_json
2010-02-22 04:16:10 +00:00
2017-01-12 10:57:34 +01:00
### Building the documentation
2014-07-01 13:09:15 +10:00
Run the Python script `doxybuild.py` from the top directory:
2010-02-22 04:16:10 +00:00
2014-07-05 13:52:15 -07:00
python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
2010-02-22 04:16:10 +00:00
2014-07-01 13:07:21 +10:00
See `doxybuild.py --help` for options.
2010-02-22 04:16:10 +00:00
2017-01-12 10:57:34 +01:00
### Adding a reader/writer test
2010-02-22 04:16:10 +00:00
To add a test, you need to create two files in test/data:
2014-07-01 13:11:05 +10:00
* a `TESTNAME.json` file, that contains the input document in JSON format.
* a `TESTNAME.expected` file, that contains a flatened representation of the
input document.
The `TESTNAME.expected` file format is as follows:
2017-01-12 10:57:34 +01:00
* Each line represents a JSON element of the element tree represented by the
2014-07-01 13:11:05 +10:00
input document.
2017-01-12 10:57:34 +01:00
* Each line has two parts: the path to access the element separated from the
2014-07-01 13:11:05 +10:00
element value by `=` . Array and object values are always empty (i.e.
represented by either `[]` or `{}` ).
2017-01-12 10:57:34 +01:00
* Element path `.` represents the root element, and is used to separate object
2014-07-01 13:11:05 +10:00
members. `[N]` is used to specify the value of an array element at index `N` .
2017-01-12 10:57:34 +01:00
See the examples `test_complex_01.json` and `test_complex_01.expected` to better understand element paths.
2010-02-22 04:16:10 +00:00
2017-01-12 10:57:34 +01:00
### Understanding reader/writer test output
When a test is run, output files are generated beside the input test files. Below is a short description of the content of each file:
2010-02-22 04:16:10 +00:00
2014-07-01 13:13:03 +10:00
* `test_complex_01.json` : input JSON document.
* `test_complex_01.expected` : flattened JSON element tree used to check if
parsing was corrected.
* `test_complex_01.actual` : flattened JSON element tree produced by `jsontest`
from reading `test_complex_01.json` .
* `test_complex_01.rewrite` : JSON document written by `jsontest` using the
`Json::Value` parsed from `test_complex_01.json` and serialized using
`Json::StyledWritter` .
* `test_complex_01.actual-rewrite` : flattened JSON element tree produced by
`jsontest` from reading `test_complex_01.rewrite` .
* `test_complex_01.process-output` : `jsontest` output, typically useful for
understanding parsing errors.
2010-04-20 21:35:19 +00:00
2017-08-27 15:16:43 -05:00
## Using JsonCpp in your project
### Amalgamated source
https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated
2018-10-18 20:12:46 +03:00
### The Meson Build System
If you are using the [Meson Build System ](http://mesonbuild.com ), then you can get a wrap file by downloading it from [Meson WrapDB ](https://wrapdb.mesonbuild.com/jsoncpp ), or simply use `meson wrap install jsoncpp` .
2017-08-27 15:16:43 -05:00
### Other ways
If you have trouble, see the Wiki, or post a question as an Issue.
2017-01-12 10:57:34 +01:00
## License
2014-07-01 13:13:46 +10:00
See the `LICENSE` file for details. In summary, JsonCpp is licensed under the
2010-04-20 21:35:19 +00:00
MIT license, or public domain if desired and recognized in your jurisdiction.