Go to file
2019-03-23 14:39:59 +01:00
.travis_scripts ENH: Refactor and enhance the CI testing infrastructure 2019-01-14 16:12:43 -06:00
devtools Restore BL's authorship attribution, and add "The Jsoncpp Authors" where it was missing. 2017-07-21 03:44:36 -07:00
doc ENH: Remove conditionals for unsupported VS compilers 2019-01-14 16:27:52 -06:00
include Implement Value::demand() 2019-03-23 14:32:13 +01:00
pkg-config Use full CMake paths in pkg-config template 2017-03-09 07:13:45 -06:00
src tests: Add a comment 2019-03-23 14:39:59 +01:00
test ENH: Refactor and enhance the CI testing infrastructure 2019-01-14 16:12:43 -06:00
.clang-format switch .clang-format to C++11 2019-01-18 07:02:16 -06:00
.gitattributes add .gitattributes 2015-08-09 16:25:36 -07:00
.gitignore Update README 2017-08-27 15:11:40 -05:00
.travis.yml ENH: Refactor and enhance the CI testing infrastructure 2019-01-14 16:12:43 -06:00
amalgamate.py Issue #872: add json/allocator.h in the amalgamated header. 2019-01-20 22:13:38 -05:00
appveyor.yml ENH: Refactor and enhance the CI testing infrastructure 2019-01-14 16:12:43 -06:00
AUTHORS Refactor authorship information for more technical accuracy. 2017-04-24 11:01:12 -07:00
CMakeLists.txt BUG: VERSION_LESS_EQUAL introduced in cmake 3.7 2019-01-18 07:00:39 -06:00
CTestConfig.cmake ENH: Refactor and enhance the CI testing infrastructure 2019-01-14 16:12:43 -06:00
dev.makefile rsync less 2017-09-10 19:55:08 -05:00
doxybuild.py Spelling (#703) 2017-12-03 10:54:29 -06:00
LICENSE Restore BL's authorship attribution, and add "The Jsoncpp Authors" where it was missing. 2017-07-21 03:44:36 -07:00
makerelease.py Spelling (#703) 2017-12-03 10:54:29 -06:00
meson.build Try to avoid empty string 2018-06-23 18:08:53 -05:00
README.md Update README.md 2019-03-20 00:12:33 -05:00
version 1.8.4; soversion=20 2017-12-20 15:07:10 -06:00
version.in generate both version.h and version from CMakelists.txt 2015-03-05 18:27:39 -06:00

JsonCpp

badge

JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value pairs.

JsonCpp is a C++ library that allows manipulating JSON values, including 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.

Documentation

JsonCpp documentation is generated using Doxygen.

A note on backward-compatibility

  • 1.y.z is built with C++11.
  • 0.y.z can be used with older compilers.
  • Major versions maintain binary-compatibility.

Contributing to JsonCpp

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.

Building and testing with Meson/Ninja

Thanks to David Seifert (@SoapGentoo), we (the maintainers) now use meson and ninja to build for debugging, as well as for continuous integration (see ./travis_scripts/meson_builder.sh ). Other systems may work, but minor things like version strings might break.

First, install both meson (which requires Python3) and ninja. 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

Then,

cd jsoncpp/
BUILD_TYPE=debug
#BUILD_TYPE=release
LIB_TYPE=shared
#LIB_TYPE=static
meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
#ninja -v -C build-${LIB_TYPE} test # This stopped working on my Mac.
ninja -v -C build-${LIB_TYPE}
cd build-${LIB_TYPE}
meson test --no-rebuild --print-errorlogs
sudo ninja install

Building and testing with other build systems

See https://github.com/open-source-parsers/jsoncpp/wiki/Building

Running the tests manually

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

# 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

# This will run the unit tests (mostly Value)
python rununittests.py path/to/test_lib_json

# You can run the tests using valgrind:
python rununittests.py --valgrind path/to/test_lib_json

Building the documentation

Run the Python script doxybuild.py from the top directory:

python doxybuild.py --doxygen=$(which doxygen) --open --with-dot

See doxybuild.py --help for options.

Adding a reader/writer test

To add a test, you need to create two files in test/data:

  • 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:

  • Each line represents a JSON element of the element tree represented by the input document.
  • Each line has two parts: the path to access the element separated from the element value by =. Array and object values are always empty (i.e. represented by either [] or {}).
  • Element path . represents the root element, and is used to separate object members. [N] is used to specify the value of an array element at index N.

See the examples test_complex_01.json and test_complex_01.expected to better understand element paths.

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:

  • 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.

Using JsonCpp in your project

Amalgamated source

https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated

The Meson Build System

If you are using the Meson Build System, then you can get a wrap file by downloading it from Meson WrapDB, or simply use meson wrap install jsoncpp.

Other ways

If you have trouble, see the Wiki, or post a question as an Issue.

License

See the LICENSE file for details. In summary, JsonCpp is licensed under the MIT license, or public domain if desired and recognized in your jurisdiction.