blob: 9188672540fb8b8def9154bc2403e34c56999e7b [file] [log] [blame]
<!-- HTML header for doxygen 1.8.7-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<title>RapidJSON: Main Page</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygenextra.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="topbanner"><a href="https://github.com/Tencent/rapidjson" title="RapidJSON GitHub"><i class="githublogo"></i></a></div>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.16 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('index.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">RapidJSON Documentation</div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><div class="image">
<img src="rapidjson.png" alt=""/>
<div class="caption">
RapidJSON logo</div></div>
<p><img src="https://img.shields.io/badge/release-v1.1.0-blue.svg" alt="Release version" class="inline"/></p>
<h2><a class="anchor" id="autotoc_md0"></a>
A fast JSON parser/generator for C++ with both SAX/DOM style API</h2>
<p>Tencent is pleased to support the open source community by making RapidJSON available.</p>
<p>Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.</p>
<ul>
<li><a href="https://github.com/Tencent/rapidjson/">RapidJSON GitHub</a></li>
<li>RapidJSON Documentation<ul>
<li><a href="http://rapidjson.org/">English</a></li>
<li><a href="http://rapidjson.org/zh-cn/">简体中文</a></li>
<li><a href="https://www.gitbook.com/book/miloyip/rapidjson/">GitBook</a> with downloadable PDF/EPUB/MOBI, without API reference.</li>
</ul>
</li>
</ul>
<h2><a class="anchor" id="autotoc_md1"></a>
Build status</h2>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadCenter"><a href="https://travis-ci.org/Tencent/rapidjson" title="Travis build status">Linux</a> </th><th class="markdownTableHeadCenter"><a href="https://ci.appveyor.com/project/miloyip/rapidjson-0fdqj/branch/master" title="AppVeyor build status">Windows</a> </th><th class="markdownTableHeadCenter"><a href="https://coveralls.io/r/Tencent/rapidjson?branch=master" title="Coveralls coverage">Coveralls</a> </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyCenter"><img src="https://travis-ci.org/Tencent/rapidjson.svg?branch=master" alt="lin-badge" title="Travis build status" class="inline"/> </td><td class="markdownTableBodyCenter"><img src="https://ci.appveyor.com/api/projects/status/l6qulgqahcayidrf/branch/master?svg=true" alt="win-badge" title="AppVeyor build status" class="inline"/> </td><td class="markdownTableBodyCenter"><img src="https://coveralls.io/repos/Tencent/rapidjson/badge.svg?branch=master" alt="cov-badge" title="Coveralls coverage" class="inline"/> </td></tr>
</table>
<h2><a class="anchor" id="autotoc_md2"></a>
Introduction</h2>
<p>RapidJSON is a JSON parser and generator for C++. It was inspired by <a href="http://rapidxml.sourceforge.net/">RapidXml</a>.</p>
<ul>
<li>RapidJSON is <b>small</b> but <b>complete</b>. It supports both SAX and DOM style API. The SAX parser is only a half thousand lines of code.</li>
<li>RapidJSON is <b>fast</b>. Its performance can be comparable to <code>strlen()</code>. It also optionally supports SSE2/SSE4.2 for acceleration.</li>
<li>RapidJSON is <b>self-contained</b> and <b>header-only</b>. It does not depend on external libraries such as BOOST. It even does not depend on STL.</li>
<li>RapidJSON is <b>memory-friendly</b>. Each JSON value occupies exactly 16 bytes for most 32/64-bit machines (excluding text string). By default it uses a fast memory allocator, and the parser allocates memory compactly during parsing.</li>
<li>RapidJSON is <b>Unicode-friendly</b>. It supports UTF-8, UTF-16, UTF-32 (LE &amp; BE), and their detection, validation and transcoding internally. For example, you can read a UTF-8 file and let RapidJSON transcode the JSON strings into UTF-16 in the DOM. It also supports surrogates and "\u0000" (null character).</li>
</ul>
<p>More features can be read <a class="el" href="md_doc_features.html">here</a>.</p>
<p>JSON(JavaScript Object Notation) is a light-weight data exchange format. RapidJSON should be in full compliance with RFC7159/ECMA-404, with optional support of relaxed syntax. More information about JSON can be obtained at</p><ul>
<li><a href="http://json.org/">Introducing JSON</a></li>
<li><a href="https://tools.ietf.org/html/rfc7159">RFC7159: The JavaScript Object Notation (JSON) Data Interchange Format</a></li>
<li><a href="https://www.ecma-international.org/publications/standards/Ecma-404.htm">Standard ECMA-404: The JSON Data Interchange Format</a></li>
</ul>
<h2><a class="anchor" id="autotoc_md3"></a>
Highlights in v1.1 (2016-8-25)</h2>
<ul>
<li>Added <a class="el" href="md_doc_pointer.html">JSON Pointer</a></li>
<li>Added <a class="el" href="md_doc_schema.html">JSON Schema</a></li>
<li>Added <a class="el" href="md_doc_dom.html">relaxed JSON syntax</a> (comment, trailing comma, NaN/Infinity)</li>
<li>Iterating array/object with <a class="el" href="md_doc_tutorial.html">C++11 Range-based for loop</a></li>
<li>Reduce memory overhead of each <code>Value</code> from 24 bytes to 16 bytes in x86-64 architecture.</li>
</ul>
<p>For other changes please refer to <a class="el" href="md__c_h_a_n_g_e_l_o_g.html">change log</a>.</p>
<h2><a class="anchor" id="autotoc_md4"></a>
Compatibility</h2>
<p>RapidJSON is cross-platform. Some platform/compiler combinations which have been tested are shown as follows.</p><ul>
<li>Visual C++ 2008/2010/2013 on Windows (32/64-bit)</li>
<li>GNU C++ 3.8.x on Cygwin</li>
<li>Clang 3.4 on Mac OS X (32/64-bit) and iOS</li>
<li>Clang 3.4 on Android NDK</li>
</ul>
<p>Users can build and run the unit tests on their platform/compiler.</p>
<h2><a class="anchor" id="autotoc_md5"></a>
Installation</h2>
<p>RapidJSON is a header-only C++ library. Just copy the <code>include/rapidjson</code> folder to system or project's include path.</p>
<p>Alternatively, if you are using the <a href="https://github.com/Microsoft/vcpkg/">vcpkg</a> dependency manager you can download and install rapidjson with CMake integration in a single command:</p><ul>
<li>vcpkg install rapidjson</li>
</ul>
<p>RapidJSON uses following software as its dependencies:</p><ul>
<li><a href="https://cmake.org/">CMake</a> as a general build tool</li>
<li>(optional) <a href="http://www.doxygen.org">Doxygen</a> to build documentation</li>
<li>(optional) <a href="https://github.com/google/googletest">googletest</a> for unit and performance testing</li>
</ul>
<p>To generate user documentation and run tests please proceed with the steps below:</p>
<ol type="1">
<li>Execute <code>git submodule update --init</code> to get the files of thirdparty submodules (google test).</li>
<li>Create directory called <code>build</code> in rapidjson source directory.</li>
<li>Change to <code>build</code> directory and run <code>cmake ..</code> command to configure your build. Windows users can do the same with cmake-gui application.</li>
<li>On Windows, build the solution found in the build directory. On Linux, run <code>make</code> from the build directory.</li>
</ol>
<p>On successful build you will find compiled test and example binaries in <code>bin</code> directory. The generated documentation will be available in <code>doc/html</code> directory of the build tree. To run tests after finished build please run <code>make test</code> or <code>ctest</code> from your build tree. You can get detailed output using <code>ctest -V</code> command.</p>
<p>It is possible to install library system-wide by running <code>make install</code> command from the build tree with administrative privileges. This will install all files according to system preferences. Once RapidJSON is installed, it is possible to use it from other CMake projects by adding <code>find_package(RapidJSON)</code> line to your CMakeLists.txt.</p>
<h2><a class="anchor" id="autotoc_md6"></a>
Usage at a glance</h2>
<p>This simple example parses a JSON string into a document (DOM), make a simple modification of the DOM, and finally stringify the DOM to a JSON string.</p>
<div class="fragment"><div class="line"><span class="comment">// rapidjson/example/simpledom/simpledom.cpp`</span></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="document_8h.html">rapidjson/document.h</a>&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;rapidjson/writer.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;rapidjson/stringbuffer.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacerapidjson.html">rapidjson</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> <span class="comment">// 1. Parse a JSON string into DOM.</span></div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span>* json = <span class="stringliteral">&quot;{\&quot;project\&quot;:\&quot;rapidjson\&quot;,\&quot;stars\&quot;:10}&quot;</span>;</div>
<div class="line"> <a class="code" href="classrapidjson_1_1_generic_document.html">Document</a> d;</div>
<div class="line"> d.<a class="code" href="classrapidjson_1_1_generic_document.html#aea842b533a858c9a3861451ad9e8642c">Parse</a>(json);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// 2. Modify it by DOM.</span></div>
<div class="line"> <a class="code" href="classrapidjson_1_1_generic_value.html">Value</a>&amp; s = d[<span class="stringliteral">&quot;stars&quot;</span>];</div>
<div class="line"> s.SetInt(s.GetInt() + 1);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// 3. Stringify the DOM</span></div>
<div class="line"> <a class="code" href="classrapidjson_1_1_generic_string_buffer.html">StringBuffer</a> buffer;</div>
<div class="line"> <a class="code" href="classrapidjson_1_1_writer.html">Writer&lt;StringBuffer&gt;</a> writer(buffer);</div>
<div class="line"> d.Accept(writer);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Output {&quot;project&quot;:&quot;rapidjson&quot;,&quot;stars&quot;:11}</span></div>
<div class="line"> std::cout &lt;&lt; buffer.GetString() &lt;&lt; std::endl;</div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p>Note that this example did not handle potential errors.</p>
<p>The following diagram shows the process.</p>
<div class="image">
<img src="simpledom.png" alt=""/>
<div class="caption">
simpledom</div></div>
<p>More <a href="https://github.com/Tencent/rapidjson/tree/master/example">examples</a> are available:</p>
<ul>
<li>DOM API<ul>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/tutorial/tutorial.cpp">tutorial</a>: Basic usage of DOM API.</li>
</ul>
</li>
<li>SAX API<ul>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/simplereader/simplereader.cpp">simplereader</a>: Dumps all SAX events while parsing a JSON by <code>Reader</code>.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/condense/condense.cpp">condense</a>: A command line tool to rewrite a JSON, with all whitespaces removed.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/pretty/pretty.cpp">pretty</a>: A command line tool to rewrite a JSON with indents and newlines by <code>PrettyWriter</code>.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/capitalize/capitalize.cpp">capitalize</a>: A command line tool to capitalize strings in JSON.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/messagereader/messagereader.cpp">messagereader</a>: Parse a JSON message with SAX API.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/serialize/serialize.cpp">serialize</a>: Serialize a C++ object into JSON with SAX API.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/jsonx/jsonx.cpp">jsonx</a>: Implements a <code>JsonxWriter</code> which stringify SAX events into <a href="https://www-01.ibm.com/support/knowledgecenter/SS9H2Y_7.1.0/com.ibm.dp.doc/json_jsonx.html">JSONx</a> (a kind of XML) format. The example is a command line tool which converts input JSON into JSONx format.</li>
</ul>
</li>
<li>Schema<ul>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/schemavalidator/schemavalidator.cpp">schemavalidator</a> : A command line tool to validate a JSON with a JSON schema.</li>
</ul>
</li>
<li>Advanced<ul>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/prettyauto/prettyauto.cpp">prettyauto</a>: A modified version of <a href="https://github.com/Tencent/rapidjson/blob/master/example/pretty/pretty.cpp">pretty</a> to automatically handle JSON with any UTF encodings.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/parsebyparts/parsebyparts.cpp">parsebyparts</a>: Implements an <code>AsyncDocumentParser</code> which can parse JSON in parts, using C++11 thread.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/filterkey/filterkey.cpp">filterkey</a>: A command line tool to remove all values with user-specified key.</li>
<li><a href="https://github.com/Tencent/rapidjson/blob/master/example/filterkeydom/filterkeydom.cpp">filterkeydom</a>: Same tool as above, but it demonstrates how to use a generator to populate a <code>Document</code>.</li>
</ul>
</li>
</ul>
<h2><a class="anchor" id="autotoc_md7"></a>
Contributing</h2>
<p>RapidJSON welcomes contributions. When contributing, please follow the code below.</p>
<h3><a class="anchor" id="autotoc_md8"></a>
Issues</h3>
<p>Feel free to submit issues and enhancement requests.</p>
<p>Please help us by providing <b>minimal reproducible examples</b>, because source code is easier to let other people understand what happens. For crash problems on certain platforms, please bring stack dump content with the detail of the OS, compiler, etc.</p>
<p>Please try breakpoint debugging first, tell us what you found, see if we can start exploring based on more information been prepared.</p>
<h3><a class="anchor" id="autotoc_md9"></a>
Workflow</h3>
<p>In general, we follow the "fork-and-pull" Git workflow.</p>
<ol type="1">
<li><b>Fork</b> the repo on GitHub</li>
<li><b>Clone</b> the project to your own machine</li>
<li><b>Checkout</b> a new branch on your fork, start developing on the branch</li>
<li><b>Test</b> the change before commit, Make sure the changes pass all the tests, including <code>unittest</code> and <code>preftest</code>, please add test case for each new feature or bug-fix if needed.</li>
<li><b>Commit</b> changes to your own branch</li>
<li><b>Push</b> your work back up to your fork</li>
<li>Submit a <b>Pull request</b> so that we can review your changes</li>
</ol>
<p>NOTE: Be sure to merge the latest from "upstream" before making a pull request!</p>
<h3><a class="anchor" id="autotoc_md10"></a>
Copyright and Licensing</h3>
<p>You can copy and paste the license summary from below.</p>
<div class="fragment"><div class="line">Tencent is pleased to support the open source community by making RapidJSON available.</div>
<div class="line"> </div>
<div class="line">Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.</div>
<div class="line"> </div>
<div class="line">Licensed under the MIT License (the &quot;License&quot;); you may not use this file except</div>
<div class="line">in compliance with the License. You may obtain a copy of the License at</div>
<div class="line"> </div>
<div class="line">http://opensource.org/licenses/MIT</div>
<div class="line"> </div>
<div class="line">Unless required by applicable law or agreed to in writing, software distributed </div>
<div class="line">under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR </div>
<div class="line">CONDITIONS OF ANY KIND, either express or implied. See the License for the </div>
<div class="line">specific language governing permissions and limitations under the License.</div>
</div><!-- fragment --> </div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="aclassrapidjson_1_1_generic_value_html"><div class="ttname"><a href="classrapidjson_1_1_generic_value.html">rapidjson::GenericValue</a></div><div class="ttdoc">Represents a JSON value. Use Value for UTF8 encoding and default allocator.</div><div class="ttdef"><b>Definition:</b> document.h:66</div></div>
<div class="ttc" id="adocument_8h_html"><div class="ttname"><a href="document_8h.html">document.h</a></div></div>
<div class="ttc" id="aclassrapidjson_1_1_generic_string_buffer_html"><div class="ttname"><a href="classrapidjson_1_1_generic_string_buffer.html">rapidjson::GenericStringBuffer</a></div><div class="ttdoc">Represents an in-memory output stream.</div><div class="ttdef"><b>Definition:</b> fwd.h:59</div></div>
<div class="ttc" id="aclassrapidjson_1_1_generic_document_html_aea842b533a858c9a3861451ad9e8642c"><div class="ttname"><a href="classrapidjson_1_1_generic_document.html#aea842b533a858c9a3861451ad9e8642c">rapidjson::GenericDocument::Parse</a></div><div class="ttdeci">GenericDocument &amp; Parse(const typename SourceEncoding::Ch *str)</div><div class="ttdoc">Parse JSON text from a read-only string (with Encoding conversion)</div><div class="ttdef"><b>Definition:</b> document.h:2692</div></div>
<div class="ttc" id="aclassrapidjson_1_1_generic_document_html"><div class="ttname"><a href="classrapidjson_1_1_generic_document.html">rapidjson::GenericDocument</a></div><div class="ttdoc">A document for parsing JSON text as DOM.</div><div class="ttdef"><b>Definition:</b> document.h:69</div></div>
<div class="ttc" id="aclassrapidjson_1_1_writer_html"><div class="ttname"><a href="classrapidjson_1_1_writer.html">rapidjson::Writer</a></div><div class="ttdoc">JSON writer.</div><div class="ttdef"><b>Definition:</b> fwd.h:95</div></div>
<div class="ttc" id="anamespacerapidjson_html"><div class="ttname"><a href="namespacerapidjson.html">rapidjson</a></div><div class="ttdoc">main RapidJSON namespace</div><div class="ttdef"><b>Definition:</b> rapidjson.h:409</div></div>
<!-- HTML footer for doxygen 1.8.7-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
</ul>
</div>
</body>
</html>