1* Introduction: 2 ============= 3 4JSON (JavaScript Object Notation) is a lightweight data-interchange format. 5It can represent integer, real number, string, an ordered sequence of 6value, and a collection of name/value pairs. 7 8JsonCpp (http://jsoncpp.sourceforge.net/) is a simple API to manipulate 9JSON value, handle serialization and unserialization to string. 10 11It can also preserve existing comment in unserialization/serialization steps, 12making it a convenient format to store user input files. 13 14Unserialization parsing is user friendly and provides precise error reports. 15 16 17* Building/Testing: 18 ================= 19 20JsonCpp uses Scons (http://www.scons.org) as a build system. Scons requires 21python to be installed (http://www.python.org). 22 23You download scons-local distribution from the following url: 24http://sourceforge.net/projects/scons/files/scons-local/1.2.0/ 25 26Unzip it in the directory where you found this README file. scons.py Should be 27at the same level as README. 28 29python scons.py platform=PLTFRM [TARGET] 30where PLTFRM may be one of: 31 suncc Sun C++ (Solaris) 32 vacpp Visual Age C++ (AIX) 33 mingw 34 msvc6 Microsoft Visual Studio 6 service pack 5-6 35 msvc70 Microsoft Visual Studio 2002 36 msvc71 Microsoft Visual Studio 2003 37 msvc80 Microsoft Visual Studio 2005 38 msvc90 Microsoft Visual Studio 2008 39 linux-gcc Gnu C++ (linux, also reported to work for Mac OS X) 40 41Notes: if you are building with Microsoft Visual Studio 2008, you need to 42setup the environment by running vcvars32.bat (e.g. MSVC 2008 command prompt) 43before running scons. 44 45Adding platform is fairly simple. You need to change the Sconstruct file 46to do so. 47 48and TARGET may be: 49 check: build library and run unit tests. 50 51 52* Running the test manually: 53 ========================== 54 55Notes that test can be run by scons using the 'check' target (see above). 56 57You need to run test manually only if you are troubleshooting an issue. 58 59In the instruction below, replace "path to jsontest.exe" with the path 60of the 'jsontest' executable that was compiled on your platform. 61 62cd test 63# This will run the Reader/Writer tests 64python runjsontests.py "path to jsontest.exe" 65 66# This will run the Reader/Writer tests, using JSONChecker test suite 67# (http://www.json.org/JSON_checker/). 68# Notes: not all tests pass: JsonCpp is too lenient (for example, 69# it allows an integer to start with '0'). The goal is to improve 70# strict mode parsing to get all tests to pass. 71python runjsontests.py --with-json-checker "path to jsontest.exe" 72 73# This will run the unit tests (mostly Value) 74python rununittests.py "path to test_lib_json.exe" 75 76You can run the tests using valgrind: 77python rununittests.py --valgrind "path to test_lib_json.exe" 78 79 80* Building the documentation: 81 =========================== 82 83Run the python script doxybuild.py from the top directory: 84 85python doxybuild.py --open --with-dot 86 87See doxybuild.py --help for options. 88 89Notes that the documentation is also available for download as a tarball. 90The documentation of the latest release is available online at: 91http://jsoncpp.sourceforge.net/ 92 93* Generating amalgamated source and header 94 ======================================== 95 96JsonCpp is provided with a script to generate a single header and a single 97source file to ease inclusion in an existing project. 98 99The amalgamated source can be generated at any time by running the following 100command from the top-directory (requires python 2.6): 101 102python amalgamate.py 103 104It is possible to specify header name. See -h options for detail. By default, 105the following files are generated: 106- dist/jsoncpp.cpp: source file that need to be added to your project 107- dist/json/json.h: header file corresponding to use in your project. It is 108equivalent to including json/json.h in non-amalgamated source. This header 109only depends on standard headers. 110- dist/json/json-forwards.h: header the provides forward declaration 111of all JsonCpp types. This typically what should be included in headers to 112speed-up compilation. 113 114The amalgamated sources are generated by concatenating JsonCpp source in the 115correct order and defining macro JSON_IS_AMALGAMATION to prevent inclusion 116of other headers. 117 118* Using json-cpp in your project: 119 =============================== 120 121include/ should be added to your compiler include path. jsoncpp headers 122should be included as follow: 123 124#include <json/json.h> 125 126 127* Adding a reader/writer test: 128 ============================ 129 130To add a test, you need to create two files in test/data: 131- a TESTNAME.json file, that contains the input document in JSON format. 132- a TESTNAME.expected file, that contains a flatened representation of 133 the input document. 134 135TESTNAME.expected file format: 136- each line represents a JSON element of the element tree represented 137 by the input document. 138- each line has two parts: the path to access the element separated from 139 the element value by '='. Array and object values are always empty 140 (e.g. represented by either [] or {}). 141- element path: '.' represented the root element, and is used to separate 142 object members. [N] is used to specify the value of an array element 143 at index N. 144See test_complex_01.json and test_complex_01.expected to better understand 145element path. 146 147 148* Understanding reader/writer test output: 149 ======================================== 150 151When a test is run, output files are generated aside the input test files. 152Below is a short description of the content of each file: 153 154- test_complex_01.json: input JSON document 155- test_complex_01.expected: flattened JSON element tree used to check if 156 parsing was corrected. 157 158- test_complex_01.actual: flattened JSON element tree produced by 159 jsontest.exe from reading test_complex_01.json 160- test_complex_01.rewrite: JSON document written by jsontest.exe using the 161 Json::Value parsed from test_complex_01.json and serialized using 162 Json::StyledWritter. 163- test_complex_01.actual-rewrite: flattened JSON element tree produced by 164 jsontest.exe from reading test_complex_01.rewrite. 165test_complex_01.process-output: jsontest.exe output, typically useful to 166 understand parsing error. 167 168* License 169 ======= 170 171See file LICENSE for details. Basically JsonCpp is licensed under 172MIT license, or public domain if desired and recognized in your jurisdiction. 173 174