Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 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. |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 7 | It can represent integer, real number, string, an ordered sequence of value, and |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 8 | a collection of name/value pairs. |
| 9 | |
| 10 | Here 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 Lepilleur | 5c5628a | 2010-12-24 19:58:23 +0000 | [diff] [blame] | 25 | "indent" : { "length" : 3, "use_space": true } |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 26 | } |
| 27 | \endverbatim |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 28 | <code>jsoncpp</code> supports comments as <i>meta-data</i>. |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 29 | |
| 30 | \section _features Features |
| 31 | - read and write JSON document |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 32 | - attach C++ style comments to element during parsing |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 33 | - rewrite JSON document preserving original comments |
| 34 | |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 35 | Notes: Comments used to be supported in JSON but where removed for |
| 36 | portability (C like comments are not supported in Python). Since |
| 37 | comments are useful in configuration/input file, this feature was |
| 38 | preserved. |
| 39 | |
| 40 | \section _example Code example |
| 41 | |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 42 | \code |
| 43 | Json::Value root; // will contains the root value after parsing. |
| 44 | Json::Reader reader; |
| 45 | bool parsingSuccessful = reader.parse( config_doc, root ); |
| 46 | if ( !parsingSuccessful ) |
| 47 | { |
| 48 | // report to the user the failure and their locations in the document. |
| 49 | std::cout << "Failed to parse configuration\n" |
Baptiste Lepilleur | b2e8ccc | 2011-05-01 16:27:55 +0000 | [diff] [blame] | 50 | << reader.getFormattedErrorMessages(); |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 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. |
| 56 | std::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. |
| 59 | const Json::Value plugins = root["plug-ins"]; |
| 60 | for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements. |
| 61 | loadPlugIn( plugins[index].asString() ); |
| 62 | |
| 63 | setIndentLength( root["indent"].get("length", 3).asInt() ); |
| 64 | setIndentUseSpace( 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 Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 69 | // necessary to explicitly construct the Json::Value object: |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 70 | root["encoding"] = getCurrentEncoding(); |
| 71 | root["indent"]["length"] = getCurrentIndentLength(); |
| 72 | root["indent"]["use_space"] = getCurrentIndentUseSpace(); |
| 73 | |
| 74 | Json::StyledWriter writer; |
| 75 | // Make a new JSON document for the configuration. Preserve original comments. |
| 76 | std::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. |
| 80 | std::cin >> root["subtree"]; |
| 81 | |
| 82 | // And you can write to a stream, using the StyledWriter automatically. |
| 83 | std::cout << root; |
| 84 | \endcode |
| 85 | |
Baptiste Lepilleur | a11e47d | 2010-03-12 10:17:46 +0000 | [diff] [blame] | 86 | \section _pbuild Build instructions |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 87 | The build instructions are located in the file |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 88 | <a HREF="https://github.com/jacobsa/jsoncpp/blob/master/README.txt">README.txt</a> in the top-directory of the project. |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 89 | |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 90 | The latest version of the source is available in the project's GitHub repository: |
| 91 | <a HREF="https://github.com/jacobsa/jsoncpp/"> |
| 92 | jsoncpp</a> |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 93 | |
Baptiste Lepilleur | 130730f | 2010-03-13 11:14:49 +0000 | [diff] [blame] | 94 | \section _news What's New? |
| 95 | The description of latest changes can be found in |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 96 | <a HREF="https://github.com/jacobsa/jsoncpp/blob/master/NEWS.txt">NEWS.txt</a> in the top-directory of the project. |
Baptiste Lepilleur | 130730f | 2010-03-13 11:14:49 +0000 | [diff] [blame] | 97 | |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 98 | <strong>TODO</strong>: Move to wiki. |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 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 | |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 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 | |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 112 | \section _license License |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 113 | See file <a href="https://github.com/jacobsa/jsoncpp/blob/master/LICENSE"><code>LICENSE</code></a> in the top-directory of the project. |
Baptiste Lepilleur | 7469f1d | 2010-04-20 21:35:19 +0000 | [diff] [blame] | 114 | |
| 115 | Basically JsonCpp is licensed under MIT license, or public domain if desired |
| 116 | and recognized in your jurisdiction. |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 117 | |
Christopher Dunn | 35bea41 | 2014-07-05 12:13:37 -0700 | [diff] [blame] | 118 | \author Baptiste Lepilleur <blep@users.sourceforge.net> (originator) |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 119 | */ |