blob: a9ed47ec4e939b6233d33f70701ab64fdd73199d [file] [log] [blame]
Christopher Dunne0d72242007-06-14 17:58:59 +00001/**
2\mainpage
3\section _intro Introduction
4
5<a HREF="http://www.json.org/">JSON (JavaScript Object Notation)</a>
6 is a lightweight data-interchange format.
Baptiste Lepilleure6a77412010-03-11 21:02:26 +00007It can represent integer, real number, string, an ordered sequence of value, and
Christopher Dunne0d72242007-06-14 17:58:59 +00008a collection of name/value pairs.
9
10Here is an example of JSON data:
11\verbatim
12// Configuration options
13{
14 // Default encoding for text
15 "encoding" : "UTF-8",
16
17 // Plug-ins loaded at start-up
18 "plug-ins" : [
19 "python",
20 "c++",
21 "ruby"
22 ],
23
24 // Tab indent size
Baptiste Lepilleur5c5628a2010-12-24 19:58:23 +000025 "indent" : { "length" : 3, "use_space": true }
Christopher Dunne0d72242007-06-14 17:58:59 +000026}
27\endverbatim
Christopher Dunn35bea412014-07-05 12:13:37 -070028<code>jsoncpp</code> supports comments as <i>meta-data</i>.
Christopher Dunne0d72242007-06-14 17:58:59 +000029
30\section _features Features
31- read and write JSON document
Christopher Dunn35bea412014-07-05 12:13:37 -070032- attach C++ style comments to element during parsing
Christopher Dunne0d72242007-06-14 17:58:59 +000033- rewrite JSON document preserving original comments
34
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000035Notes: Comments used to be supported in JSON but where removed for
36portability (C like comments are not supported in Python). Since
37comments are useful in configuration/input file, this feature was
38preserved.
39
40\section _example Code example
41
Christopher Dunne0d72242007-06-14 17:58:59 +000042\code
43Json::Value root; // will contains the root value after parsing.
44Json::Reader reader;
45bool parsingSuccessful = reader.parse( config_doc, root );
46if ( !parsingSuccessful )
47{
48 // report to the user the failure and their locations in the document.
49 std::cout << "Failed to parse configuration\n"
Baptiste Lepilleurb2e8ccc2011-05-01 16:27:55 +000050 << reader.getFormattedErrorMessages();
Christopher Dunne0d72242007-06-14 17:58:59 +000051 return;
52}
53
54// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
55// such member.
56std::string encoding = root.get("encoding", "UTF-8" ).asString();
57// Get the value of the member of root named 'encoding', return a 'null' value if
58// there is no such member.
59const Json::Value plugins = root["plug-ins"];
60for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
61 loadPlugIn( plugins[index].asString() );
62
63setIndentLength( root["indent"].get("length", 3).asInt() );
64setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
65
66// ...
67// At application shutdown to make the new configuration document:
68// Since Json::Value has implicit constructor for all value types, it is not
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000069// necessary to explicitly construct the Json::Value object:
Christopher Dunne0d72242007-06-14 17:58:59 +000070root["encoding"] = getCurrentEncoding();
71root["indent"]["length"] = getCurrentIndentLength();
72root["indent"]["use_space"] = getCurrentIndentUseSpace();
73
74Json::StyledWriter writer;
75// Make a new JSON document for the configuration. Preserve original comments.
76std::string outputConfig = writer.write( root );
77
78// You can also use streams. This will put the contents of any JSON
79// stream at a particular sub-value, if you'd like.
80std::cin >> root["subtree"];
81
82// And you can write to a stream, using the StyledWriter automatically.
83std::cout << root;
84\endcode
85
Baptiste Lepilleura11e47d2010-03-12 10:17:46 +000086\section _pbuild Build instructions
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000087The build instructions are located in the file
Christopher Dunn5a651322014-07-05 20:44:33 -070088<a HREF="https://github.com/open-source-parsers/jsoncpp/blob/master/README.md">README.md</a> in the top-directory of the project.
Christopher Dunne0d72242007-06-14 17:58:59 +000089
Christopher Dunn35bea412014-07-05 12:13:37 -070090The latest version of the source is available in the project's GitHub repository:
Christopher Dunnbef834e2014-07-05 19:05:10 -070091<a HREF="https://github.com/open-source-parsers/jsoncpp/">
Christopher Dunn35bea412014-07-05 12:13:37 -070092jsoncpp</a>
Christopher Dunne0d72242007-06-14 17:58:59 +000093
Baptiste Lepilleur130730f2010-03-13 11:14:49 +000094\section _news What's New?
95The description of latest changes can be found in
Christopher Dunn5a651322014-07-05 20:44:33 -070096<a HREF="https://github.com/open-source-parsers/jsoncpp/wiki/NEWS">
97 the NEWS wiki
98</a>.
Christopher Dunne0d72242007-06-14 17:58:59 +000099
100\section _rlinks Related links
101- <a HREF="http://www.json.org/">JSON</a> Specification and alternate language implementations.
102- <a HREF="http://www.yaml.org/">YAML</a> A data format designed for human readability.
103- <a HREF="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ</a>.
104
Christopher Dunn35bea412014-07-05 12:13:37 -0700105\section _plinks Old project links
106- <a href="https://sourceforge.net/projects/jsoncpp/">https://sourceforge.net/projects/jsoncpp/</a>
107- <a href="http://jsoncpp.sourceforge.net">http://jsoncpp.sourceforge.net</a>
108- <a href="http://sourceforge.net/projects/jsoncpp/files/">http://sourceforge.net/projects/jsoncpp/files/</a>
109- <a href="http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/">http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/</a>
110- <a href="http://jsoncpp.sourceforge.net/old.html">http://jsoncpp.sourceforge.net/old.html</a>
111
Christopher Dunne0d72242007-06-14 17:58:59 +0000112\section _license License
Christopher Dunnbef834e2014-07-05 19:05:10 -0700113See file <a href="https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE"><code>LICENSE</code></a> in the top-directory of the project.
Baptiste Lepilleur7469f1d2010-04-20 21:35:19 +0000114
115Basically JsonCpp is licensed under MIT license, or public domain if desired
116and recognized in your jurisdiction.
Christopher Dunne0d72242007-06-14 17:58:59 +0000117
Christopher Dunn35bea412014-07-05 12:13:37 -0700118\author Baptiste Lepilleur <blep@users.sourceforge.net> (originator)
Christopher Dunne0d72242007-06-14 17:58:59 +0000119*/