1 * Introduction: 2 ============= 3 4 JSON (JavaScript Object Notation) is a lightweight data-interchange format. 5 It can represent integer, real number, string, an ordered sequence of 6 value, and a collection of name/value pairs. 7 8 JsonCpp (http://jsoncpp.sourceforge.net/) is a simple API to manipulate 9 JSON value, handle serialization and unserialization to string. 10 11 It can also preserve existing comment in unserialization/serialization steps, 12 making it a convenient format to store user input files. 13 14 Unserialization parsing is user friendly and provides precise error reports. 15 16 17 * Building/Testing: 18 ================= 19 20 JsonCpp uses Scons (http://www.scons.org) as a build system. Scons requires 21 python to be installed (http://www.python.org). 22 23 You download scons-local distribution from the following url: 24 http://sourceforge.net/projects/scons/files/scons-local/1.2.0/ 25 26 Unzip it in the directory where you found this README file. scons.py Should be 27 at the same level as README. 28 29 python scons.py platform=PLTFRM [TARGET] 30 where 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 41 Notes: if you are building with Microsoft Visual Studio 2008, you need to 42 setup the environment by running vcvars32.bat (e.g. MSVC 2008 command prompt) 43 before running scons. 44 45 Adding platform is fairly simple. You need to change the Sconstruct file 46 to do so. 47 48 and TARGET may be: 49 check: build library and run unit tests. 50 51 52 * Running the test manually: 53 ========================== 54 55 Notes that test can be run by scons using the 'check' target (see above). 56 57 You need to run test manually only if you are troubleshooting an issue. 58 59 In the instruction below, replace "path to jsontest.exe" with the path 60 of the 'jsontest' executable that was compiled on your platform. 61 62 cd test 63 # This will run the Reader/Writer tests 64 python 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. 71 python runjsontests.py --with-json-checker "path to jsontest.exe" 72 73 # This will run the unit tests (mostly Value) 74 python rununittests.py "path to test_lib_json.exe" 75 76 You can run the tests using valgrind: 77 python rununittests.py --valgrind "path to test_lib_json.exe" 78 79 80 * Building the documentation: 81 =========================== 82 83 Run the python script doxybuild.py from the top directory: 84 85 python doxybuild.py --open --with-dot 86 87 See doxybuild.py --help for options. 88 89 Notes that the documentation is also available for download as a tarball. 90 The documentation of the latest release is available online at: 91 http://jsoncpp.sourceforge.net/ 92 93 * Generating amalgamated source and header 94 ======================================== 95 96 JsonCpp is provided with a script to generate a single header and a single 97 source file to ease inclusion in an existing project. 98 99 The amalgamated source can be generated at any time by running the following 100 command from the top-directory (requires python 2.6): 101 102 python amalgamate.py 103 104 It is possible to specify header name. See -h options for detail. By default, 105 the 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 108 equivalent to including json/json.h in non-amalgamated source. This header 109 only depends on standard headers. 110 - dist/json/json-forwards.h: header the provides forward declaration 111 of all JsonCpp types. This typically what should be included in headers to 112 speed-up compilation. 113 114 The amalgamated sources are generated by concatenating JsonCpp source in the 115 correct order and defining macro JSON_IS_AMALGAMATION to prevent inclusion 116 of other headers. 117 118 * Using json-cpp in your project: 119 =============================== 120 121 include/ should be added to your compiler include path. jsoncpp headers 122 should be included as follow: 123 124 #include <json/json.h> 125 126 127 * Adding a reader/writer test: 128 ============================ 129 130 To 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 135 TESTNAME.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. 144 See test_complex_01.json and test_complex_01.expected to better understand 145 element path. 146 147 148 * Understanding reader/writer test output: 149 ======================================== 150 151 When a test is run, output files are generated aside the input test files. 152 Below 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. 165 test_complex_01.process-output: jsontest.exe output, typically useful to 166 understand parsing error. 167 168 * License 169 ======= 170 171 See file LICENSE for details. Basically JsonCpp is licensed under 172 MIT license, or public domain if desired and recognized in your jurisdiction. 173 174