blob: 1cde6ff1ab256134d879d3ae2c50b470cd4b576b [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 Lepilleur43e25c32009-11-19 19:03:14 +000025 "indent" : { "length" : 3, "use_space" = true }
Christopher Dunne0d72242007-06-14 17:58:59 +000026}
27\endverbatim
28
29\section _features Features
30- read and write JSON document
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000031- attach C and C++ style comments to element during parsing
Christopher Dunne0d72242007-06-14 17:58:59 +000032- rewrite JSON document preserving original comments
33
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000034Notes: Comments used to be supported in JSON but where removed for
35portability (C like comments are not supported in Python). Since
36comments are useful in configuration/input file, this feature was
37preserved.
38
39\section _example Code example
40
Christopher Dunne0d72242007-06-14 17:58:59 +000041\code
42Json::Value root; // will contains the root value after parsing.
43Json::Reader reader;
44bool parsingSuccessful = reader.parse( config_doc, root );
45if ( !parsingSuccessful )
46{
47 // report to the user the failure and their locations in the document.
48 std::cout << "Failed to parse configuration\n"
49 << reader.getFormatedErrorMessages();
50 return;
51}
52
53// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
54// such member.
55std::string encoding = root.get("encoding", "UTF-8" ).asString();
56// Get the value of the member of root named 'encoding', return a 'null' value if
57// there is no such member.
58const Json::Value plugins = root["plug-ins"];
59for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
60 loadPlugIn( plugins[index].asString() );
61
62setIndentLength( root["indent"].get("length", 3).asInt() );
63setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
64
65// ...
66// At application shutdown to make the new configuration document:
67// Since Json::Value has implicit constructor for all value types, it is not
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000068// necessary to explicitly construct the Json::Value object:
Christopher Dunne0d72242007-06-14 17:58:59 +000069root["encoding"] = getCurrentEncoding();
70root["indent"]["length"] = getCurrentIndentLength();
71root["indent"]["use_space"] = getCurrentIndentUseSpace();
72
73Json::StyledWriter writer;
74// Make a new JSON document for the configuration. Preserve original comments.
75std::string outputConfig = writer.write( root );
76
77// You can also use streams. This will put the contents of any JSON
78// stream at a particular sub-value, if you'd like.
79std::cin >> root["subtree"];
80
81// And you can write to a stream, using the StyledWriter automatically.
82std::cout << root;
83\endcode
84
Baptiste Lepilleura11e47d2010-03-12 10:17:46 +000085\section _pbuild Build instructions
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000086The build instructions are located in the file
Christopher Dunne0d72242007-06-14 17:58:59 +000087<a HREF="README.txt">README.txt</a> in the top-directory of the project.
88
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000089Permanent link to the latest revision of the file in subversion:
90<a HREF="http://svn.sourceforge.net/viewcvs.cgi/jsoncpp/README.txt?view=markup">latest README.txt</a>
91
92\section _pdownload Download
93The sources can be downloaded from
94<a HREF="http://sourceforge.net/projects/jsoncpp/files/">SourceForge download page</a>.
95
96The latest version of the source is available in the project's subversion repository:
97<a HREF="http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/">
98http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/</a>
99
100To checkout the source, see the following
101<a HREF="http://sourceforge.net/scm/?type=svn&group_id=144446">instructions</a>.
Christopher Dunne0d72242007-06-14 17:58:59 +0000102
Baptiste Lepilleur130730f2010-03-13 11:14:49 +0000103\section _news What's New?
104The description of latest changes can be found in
105<a HREF="NEWS.txt">NEWS.txt</a> in the top-directory of the project.
106
107Permanent link to the latest revision of the file in subversion:
108<a HREF="http://svn.sourceforge.net/viewcvs.cgi/jsoncpp/README.txt?view=markup">latest NEWS.txt</a>
109
Christopher Dunne0d72242007-06-14 17:58:59 +0000110\section _plinks Project links
111- <a HREF="http://jsoncpp.sourceforge.net">json-cpp home</a>
112- <a HREF="http://www.sourceforge.net/projects/jsoncpp">json-cpp sourceforge project</a>
113
114\section _rlinks Related links
115- <a HREF="http://www.json.org/">JSON</a> Specification and alternate language implementations.
116- <a HREF="http://www.yaml.org/">YAML</a> A data format designed for human readability.
117- <a HREF="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ</a>.
118
119\section _license License
120The json-cpp library and this documentation are in Public Domain.
121
122\author Baptiste Lepilleur <blep@users.sourceforge.net>
123*/