• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..11-Apr-2017-

include/json/H11-Apr-2017-2,093999

src/lib_json/H11-Apr-2017-5,1794,422

AUTHORSH A D11-Apr-201748 21

GIT-INFOH A D11-Apr-201741 21

LICENSEH A D11-Apr-20172.6 KiB5644

README.mdH A D11-Apr-20178.1 KiB215160

README.md

1Introduction
2------------
3
4[JSON][json-org] is a lightweight data-interchange format. It can represent
5numbers, strings, ordered sequences of values, and collections of name/value
6pairs.
7
8[json-org]: http://json.org/
9
10[JsonCpp][] is a C++ library that allows manipulating JSON values, including
11serialization and deserialization to and from strings. It can also preserve
12existing comment in unserialization/serialization steps, making it a convenient
13format to store user input files.
14
15[JsonCpp]: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html
16
17## A note on backward-compatibility
18* `1.y.z` is built with C++11.
19* `0.y.z` can be used with older compilers.
20* Major versions maintain binary-compatibility.
21
22# Using JsonCpp in your project
23-----------------------------
24The recommended approach to integrating JsonCpp in your project is to include
25the [amalgamated source](#generating-amalgamated-source-and-header) (a single
26`.cpp` file and two `.h` files) in your project, and compile and build as you
27would any other source file. This ensures consistency of compilation flags and
28ABI compatibility, issues which arise when building shared or static
29libraries. See the next section for instructions.
30
31The `include/` should be added to your compiler include path. Jsoncpp headers
32should be included as follow:
33
34    #include <json/json.h>
35
36If JsonCpp was built as a dynamic library on Windows, then your project needs to
37define the macro `JSON_DLL`.
38
39Generating amalgamated source and header
40----------------------------------------
41JsonCpp is provided with a script to generate a single header and a single
42source file to ease inclusion into an existing project. The amalgamated source
43can be generated at any time by running the following command from the
44top-directory (this requires Python 2.6):
45
46    python amalgamate.py
47
48It is possible to specify header name. See the `-h` option for detail.
49
50By default, the following files are generated:
51* `dist/jsoncpp.cpp`: source file that needs to be added to your project.
52* `dist/json/json.h`: corresponding header file for use in your project. It is
53  equivalent to including `json/json.h` in non-amalgamated source. This header
54  only depends on standard headers.
55* `dist/json/json-forwards.h`: header that provides forward declaration of all
56  JsonCpp types.
57
58The amalgamated sources are generated by concatenating JsonCpp source in the
59correct order and defining the macro `JSON_IS_AMALGAMATION` to prevent inclusion
60of other headers.
61
62# Contributing to JsonCpp
63
64Building and testing with CMake
65-------------------------------
66[CMake][] is a C++ Makefiles/Solution generator. It is usually available on most
67Linux system as package. On Ubuntu:
68
69    sudo apt-get install cmake
70
71[CMake]: http://www.cmake.org
72
73Note that Python is also required to run the JSON reader/writer tests. If
74missing, the build will skip running those tests.
75
76When running CMake, a few parameters are required:
77
78* a build directory where the makefiles/solution are generated. It is also used
79  to store objects, libraries and executables files.
80* the generator to use: makefiles or Visual Studio solution? What version or
81  Visual Studio, 32 or 64 bits solution?
82
83Steps for generating solution/makefiles using `cmake-gui`:
84
85* Make "source code" point to the source directory.
86* Make "where to build the binary" point to the directory to use for the build.
87* Click on the "Grouped" check box.
88* Review JsonCpp build options (tick `BUILD_SHARED_LIBS` to build as a
89  dynamic library).
90* Click the configure button at the bottom, then the generate button.
91* The generated solution/makefiles can be found in the binary directory.
92
93Alternatively, from the command-line on Unix in the source directory:
94
95    mkdir -p build/debug
96    cd build/debug
97    cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../..
98    make
99
100Running `cmake -h` will display the list of available generators (passed using
101the `-G` option).
102
103By default CMake hides compilation commands. This can be modified by specifying
104`-DCMAKE_VERBOSE_MAKEFILE=true` when generating makefiles.
105
106Building and testing with SCons
107-------------------------------
108**Note:** The SCons-based build system is deprecated. Please use CMake; see the
109section above.
110
111JsonCpp can use [Scons][] as a build system. Note that SCons requires Python to
112be installed.
113
114[SCons]: http://www.scons.org/
115
116Invoke SCons as follows:
117
118    scons platform=$PLATFORM [TARGET]
119
120where `$PLATFORM` may be one of:
121
122* `suncc`: Sun C++ (Solaris)
123* `vacpp`: Visual Age C++ (AIX)
124* `mingw`
125* `msvc6`: Microsoft Visual Studio 6 service pack 5-6
126* `msvc70`: Microsoft Visual Studio 2002
127* `msvc71`: Microsoft Visual Studio 2003
128* `msvc80`: Microsoft Visual Studio 2005
129* `msvc90`: Microsoft Visual Studio 2008
130* `linux-gcc`: Gnu C++ (linux, also reported to work for Mac OS X)
131
132If you are building with Microsoft Visual Studio 2008, you need to set up the
133environment by running `vcvars32.bat` (e.g. MSVC 2008 command prompt) before
134running SCons.
135
136## Running the tests manually
137You need to run tests manually only if you are troubleshooting an issue.
138
139In the instructions below, replace `path/to/jsontest` with the path of the
140`jsontest` executable that was compiled on your platform.
141
142    cd test
143    # This will run the Reader/Writer tests
144    python runjsontests.py path/to/jsontest
145
146    # This will run the Reader/Writer tests, using JSONChecker test suite
147    # (http://www.json.org/JSON_checker/).
148    # Notes: not all tests pass: JsonCpp is too lenient (for example,
149    # it allows an integer to start with '0'). The goal is to improve
150    # strict mode parsing to get all tests to pass.
151    python runjsontests.py --with-json-checker path/to/jsontest
152
153    # This will run the unit tests (mostly Value)
154    python rununittests.py path/to/test_lib_json
155
156    # You can run the tests using valgrind:
157    python rununittests.py --valgrind path/to/test_lib_json
158
159## Running the tests using scons
160Note that tests can be run using SCons using the `check` target:
161
162    scons platform=$PLATFORM check
163
164Building the documentation
165--------------------------
166Run the Python script `doxybuild.py` from the top directory:
167
168    python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
169
170See `doxybuild.py --help` for options.
171
172Adding a reader/writer test
173---------------------------
174To add a test, you need to create two files in test/data:
175
176* a `TESTNAME.json` file, that contains the input document in JSON format.
177* a `TESTNAME.expected` file, that contains a flatened representation of the
178  input document.
179
180The `TESTNAME.expected` file format is as follows:
181
182* each line represents a JSON element of the element tree represented by the
183  input document.
184* each line has two parts: the path to access the element separated from the
185  element value by `=`. Array and object values are always empty (i.e.
186  represented by either `[]` or `{}`).
187* element path: `.` represents the root element, and is used to separate object
188  members. `[N]` is used to specify the value of an array element at index `N`.
189
190See the examples `test_complex_01.json` and `test_complex_01.expected` to better
191understand element paths.
192
193Understanding reader/writer test output
194---------------------------------------
195When a test is run, output files are generated beside the input test files.
196Below is a short description of the content of each file:
197
198* `test_complex_01.json`: input JSON document.
199* `test_complex_01.expected`: flattened JSON element tree used to check if
200  parsing was corrected.
201* `test_complex_01.actual`: flattened JSON element tree produced by `jsontest`
202  from reading `test_complex_01.json`.
203* `test_complex_01.rewrite`: JSON document written by `jsontest` using the
204  `Json::Value` parsed from `test_complex_01.json` and serialized using
205  `Json::StyledWritter`.
206* `test_complex_01.actual-rewrite`: flattened JSON element tree produced by
207  `jsontest` from reading `test_complex_01.rewrite`.
208* `test_complex_01.process-output`: `jsontest` output, typically useful for
209  understanding parsing errors.
210
211License
212-------
213See the `LICENSE` file for details. In summary, JsonCpp is licensed under the
214MIT license, or public domain if desired and recognized in your jurisdiction.
215