• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
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.
7It can represent integer, real number, string, an ordered sequence of value, and
8a 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
25    "indent" : { "length" : 3, "use_space": true }
26}
27\endverbatim
28<code>jsoncpp</code> supports comments as <i>meta-data</i>.
29
30\section _features Features
31- read and write JSON document
32- attach C++ style comments to element during parsing
33- rewrite JSON document preserving original comments
34
35Notes: 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
42\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"
50               << reader.getFormattedErrorMessages();
51    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
69// necessary to explicitly construct the Json::Value object:
70root["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
86\section _pbuild Build instructions
87The build instructions are located in the file
88<a HREF="https://github.com/open-source-parsers/jsoncpp/blob/master/README.md">README.md</a> in the top-directory of the project.
89
90The latest version of the source is available in the project's GitHub repository:
91<a HREF="https://github.com/open-source-parsers/jsoncpp/">
92jsoncpp</a>
93
94\section _news What's New?
95The description of latest changes can be found in
96<a HREF="https://github.com/open-source-parsers/jsoncpp/wiki/NEWS">
97  the NEWS wiki
98</a>.
99
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
105\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
112\section _license License
113See file <a href="https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE"><code>LICENSE</code></a> in the top-directory of the project.
114
115Basically JsonCpp is licensed under MIT license, or public domain if desired
116and recognized in your jurisdiction.
117
118\author Baptiste Lepilleur <blep@users.sourceforge.net> (originator)
119*/
120