blob: acde674fb0ad71c4837d01b965cbf2164ad31d5c [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.
Christopher Dunne0d72242007-06-14 17:58:59 +00007
8Here is an example of JSON data:
9\verbatim
Christopher Dunn948f2902015-01-25 12:19:30 -060010{
11 "encoding" : "UTF-8",
12 "plug-ins" : [
13 "python",
14 "c++",
15 "ruby"
16 ],
17 "indent" : { "length" : 3, "use_space": true }
18}
19\endverbatim
20<b>JsonCpp</b> supports comments as <i>meta-data</i>:
21\code
Christopher Dunne0d72242007-06-14 17:58:59 +000022// Configuration options
23{
24 // Default encoding for text
25 "encoding" : "UTF-8",
26
27 // Plug-ins loaded at start-up
28 "plug-ins" : [
29 "python",
Christopher Dunn948f2902015-01-25 12:19:30 -060030 "c++", // trailing comment
Christopher Dunne0d72242007-06-14 17:58:59 +000031 "ruby"
32 ],
33
34 // Tab indent size
Christopher Dunn948f2902015-01-25 12:19:30 -060035 // (multi-line comment)
36 "indent" : { /*embedded comment*/ "length" : 3, "use_space": true }
Christopher Dunne0d72242007-06-14 17:58:59 +000037}
Christopher Dunn948f2902015-01-25 12:19:30 -060038\endcode
Christopher Dunne0d72242007-06-14 17:58:59 +000039
40\section _features Features
41- read and write JSON document
Christopher Dunn35bea412014-07-05 12:13:37 -070042- attach C++ style comments to element during parsing
Christopher Dunne0d72242007-06-14 17:58:59 +000043- rewrite JSON document preserving original comments
44
Christopher Dunn948f2902015-01-25 12:19:30 -060045Notes: Comments used to be supported in JSON but were removed for
Baptiste Lepilleure6a77412010-03-11 21:02:26 +000046portability (C like comments are not supported in Python). Since
47comments are useful in configuration/input file, this feature was
48preserved.
49
50\section _example Code example
51
Christopher Dunne0d72242007-06-14 17:58:59 +000052\code
Christopher Dunn66a8ba22015-02-09 01:29:43 -060053Json::Value root; // 'root' will contain the root value after parsing.
Christopher Dunnf3b33582015-02-09 11:51:06 -060054std::cin >> root;
Christopher Dunne0d72242007-06-14 17:58:59 +000055
56// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
57// such member.
58std::string encoding = root.get("encoding", "UTF-8" ).asString();
59// Get the value of the member of root named 'encoding', return a 'null' value if
60// there is no such member.
61const Json::Value plugins = root["plug-ins"];
62for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
63 loadPlugIn( plugins[index].asString() );
64
65setIndentLength( root["indent"].get("length", 3).asInt() );
66setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
67
Christopher Dunne0d72242007-06-14 17:58:59 +000068// 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
Christopher Dunnc7b39c22015-01-25 18:45:59 -060074// If you like the defaults, you can insert directly into a stream.
Christopher Dunnf3b33582015-02-09 11:51:06 -060075std::cout << root;
76// Of course, you can write to `std::ostringstream` if you prefer.
Christopher Dunnc7b39c22015-01-25 18:45:59 -060077
Christopher Dunn28a20912015-01-26 10:43:39 -060078// If desired, remember to add a linefeed and flush.
79std::cout << std::endl;
Christopher Dunn8df98f62015-02-09 11:15:39 -060080\endcode
Christopher Dunn28a20912015-01-26 10:43:39 -060081
Christopher Dunn8df98f62015-02-09 11:15:39 -060082\section _advanced Advanced usage
Christopher Dunnf3b33582015-02-09 11:51:06 -060083We are finalizing the new *Builder* API, which will be in versions
84`1.4.0` and `0.8.0` when released. Until then, you may continue to
85use the old API, include `Writer`, `Reader`, and `Feature`.
Christopher Dunn8df98f62015-02-09 11:15:39 -060086\code
Christopher Dunnf3b33582015-02-09 11:51:06 -060087
88// EXPERIMENTAL
89// Or use `writeString()` for convenience, with a specialized builder.
Christopher Dunn8df98f62015-02-09 11:15:39 -060090Json::StreamWriterBuilder wbuilder;
91builder.indentation_ = "\t";
92std::string document = Json::writeString(root, wbuilder);
Christopher Dunn9da9f842015-01-25 19:20:43 -060093
Christopher Dunn64514122015-02-09 09:44:26 -060094// You can also read into a particular sub-value.
Christopher Dunne0d72242007-06-14 17:58:59 +000095std::cin >> root["subtree"];
Christopher Dunn8df98f62015-02-09 11:15:39 -060096
Christopher Dunnf3b33582015-02-09 11:51:06 -060097// EXPERIMENTAL
Christopher Dunn8df98f62015-02-09 11:15:39 -060098// Here we use a specialized Builder, discard comments, and
99// record errors.
100Json::CharReaderBuilder rbuilder;
101rbuilder.collectComments_ = false;
102std::string errs;
103Json::parseFromStream(rbuilder, std::cin, &root["subtree"], &errs);
Christopher Dunne0d72242007-06-14 17:58:59 +0000104\endcode
105
Baptiste Lepilleura11e47d2010-03-12 10:17:46 +0000106\section _pbuild Build instructions
Baptiste Lepilleure6a77412010-03-11 21:02:26 +0000107The build instructions are located in the file
Christopher Dunn5a651322014-07-05 20:44:33 -0700108<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 +0000109
Christopher Dunn35bea412014-07-05 12:13:37 -0700110The latest version of the source is available in the project's GitHub repository:
Christopher Dunnbef834e2014-07-05 19:05:10 -0700111<a HREF="https://github.com/open-source-parsers/jsoncpp/">
Christopher Dunn35bea412014-07-05 12:13:37 -0700112jsoncpp</a>
Christopher Dunne0d72242007-06-14 17:58:59 +0000113
Baptiste Lepilleur130730f2010-03-13 11:14:49 +0000114\section _news What's New?
115The description of latest changes can be found in
Christopher Dunn5a651322014-07-05 20:44:33 -0700116<a HREF="https://github.com/open-source-parsers/jsoncpp/wiki/NEWS">
117 the NEWS wiki
118</a>.
Christopher Dunne0d72242007-06-14 17:58:59 +0000119
120\section _rlinks Related links
121- <a HREF="http://www.json.org/">JSON</a> Specification and alternate language implementations.
122- <a HREF="http://www.yaml.org/">YAML</a> A data format designed for human readability.
123- <a HREF="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ</a>.
124
Christopher Dunn35bea412014-07-05 12:13:37 -0700125\section _plinks Old project links
126- <a href="https://sourceforge.net/projects/jsoncpp/">https://sourceforge.net/projects/jsoncpp/</a>
127- <a href="http://jsoncpp.sourceforge.net">http://jsoncpp.sourceforge.net</a>
128- <a href="http://sourceforge.net/projects/jsoncpp/files/">http://sourceforge.net/projects/jsoncpp/files/</a>
129- <a href="http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/">http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/</a>
130- <a href="http://jsoncpp.sourceforge.net/old.html">http://jsoncpp.sourceforge.net/old.html</a>
131
Christopher Dunne0d72242007-06-14 17:58:59 +0000132\section _license License
Christopher Dunnbef834e2014-07-05 19:05:10 -0700133See 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 +0000134
135Basically JsonCpp is licensed under MIT license, or public domain if desired
136and recognized in your jurisdiction.
Christopher Dunne0d72242007-06-14 17:58:59 +0000137
Christopher Dunn35bea412014-07-05 12:13:37 -0700138\author Baptiste Lepilleur <blep@users.sourceforge.net> (originator)
Christopher Dunn249fd182015-02-09 00:46:20 -0600139\version \include version
140\sa version.h
Christopher Dunne0d72242007-06-14 17:58:59 +0000141*/