You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=11"/>
  6. <meta name="generator" content="Doxygen 1.9.4"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>json-c: json-c</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  13. </head>
  14. <body>
  15. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  16. <div id="titlearea">
  17. <table cellspacing="0" cellpadding="0">
  18. <tbody>
  19. <tr id="projectrow">
  20. <td id="projectalign">
  21. <div id="projectname">json-c<span id="projectnumber">&#160;0.18</span>
  22. </div>
  23. </td>
  24. </tr>
  25. </tbody>
  26. </table>
  27. </div>
  28. <!-- end header part -->
  29. <!-- Generated by Doxygen 1.9.4 -->
  30. <script type="text/javascript" src="menudata.js"></script>
  31. <script type="text/javascript" src="menu.js"></script>
  32. <script type="text/javascript">
  33. /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  34. $(function() {
  35. initMenu('',false,false,'search.php','Search');
  36. });
  37. /* @license-end */
  38. </script>
  39. <div id="main-nav"></div>
  40. </div><!-- top -->
  41. <div><div class="header">
  42. <div class="headertitle"><div class="title">json-c </div></div>
  43. </div><!--header-->
  44. <div class="contents">
  45. <div class="textblock"><h1><a class="anchor" id="autotoc_md0"></a>
  46. json-c</h1>
  47. <ol type="1">
  48. <li><a class="el" href="index.html#overview">Overview and Build Status</a></li>
  49. <li><a class="el" href="index.html#gettinghelp">Getting Help</a></li>
  50. <li><a class="el" href="index.html#buildunix">Building on Unix</a><ul>
  51. <li><a class="el" href="index.html#installprereq">Prerequisites</a></li>
  52. <li><a class="el" href="index.html#buildcmds">Build commands</a></li>
  53. </ul>
  54. </li>
  55. <li><a class="el" href="index.html#CMake">CMake options</a></li>
  56. <li><a class="el" href="index.html#testing">Testing</a></li>
  57. <li><a class="el" href="index.html#buildvcpkg">Building with `vcpkg`</a></li>
  58. <li><a class="el" href="index.html#android">Building for Android</a></li>
  59. </ol>
  60. <ol type="1">
  61. <li><a class="el" href="index.html#linking">Linking to libjson-c</a></li>
  62. <li><a class="el" href="index.html#using">Using json-c</a></li>
  63. </ol>
  64. <p ><a class="anchor" id="overview"></a> </p>
  65. <h2><a class="anchor" id="autotoc_md1"></a>
  66. JSON-C - A JSON implementation in C</h2>
  67. <p >JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects. It aims to conform to <a href="https://www.rfc-editor.org/rfc/rfc8259">RFC 8259</a>.</p>
  68. <p >Skip down to <a class="el" href="index.html#using">Using json-c</a> or check out the <a href="https://json-c.github.io/json-c/">API docs</a>, if you already have json-c installed and ready to use.</p>
  69. <p >Home page for json-c: <a href="https://github.com/json-c/json-c/wiki">https://github.com/json-c/json-c/wiki</a></p>
  70. <p ><a class="anchor" id="gettinghelp"></a> </p>
  71. <h2><a class="anchor" id="autotoc_md2"></a>
  72. Getting Help</h2>
  73. <p >If you have questions about using json-c, please start a thread on our forums at: <a href="https://groups.google.com/forum/#!forum/json-c">https://groups.google.com/forum/#!forum/json-c</a></p>
  74. <p >If you believe you've discovered a bug, report it at (<a href="https://github.com/json-c/json-c/issues">https://github.com/json-c/json-c/issues</a>). Please be sure to include the version of json-c you're using, the OS you're running on, and any other relevant details. Fully reproducible test cases and/or patches to fix problems are greatly appreciated.</p>
  75. <p >Fixes for bugs, or small new features can be directly submitted as a <a href="https://github.com/json-c/json-c/pulls">pull request</a>. For major new features or large changes of any kind, please first start a discussion on the <a href="https://groups.google.com/forum/#!forum/json-c">forums</a>.</p>
  76. <p ><a class="anchor" id="buildunix"></a> </p>
  77. <h2><a class="anchor" id="autotoc_md3"></a>
  78. Building on Unix with &lt;tt&gt;git&lt;/tt&gt;, &lt;tt&gt;gcc&lt;/tt&gt; and &lt;tt&gt;cmake&lt;/tt&gt;</h2>
  79. <p >If you already have json-c installed, see <a class="el" href="index.html#linking">Linking to `libjson-c`</a> for how to build and link your program against it.</p>
  80. <p >Build Status</p><ul>
  81. <li><a href="https://ci.appveyor.com/project/hawicz/json-c">AppVeyor Build</a> <img src="https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&amp;svg=true" alt="AppVeyor Build Status" class="inline"/></li>
  82. <li><a href="https://app.travis-ci.com/github/json-c/json-c">Travis Build</a> <img src="https://api.travis-ci.com/json-c/json-c.svg?branch=master" alt="Travis Build Status" style="pointer-events: none;" class="inline"/></li>
  83. </ul>
  84. <p >Test Status</p><ul>
  85. <li><a href="https://coveralls.io/github/json-c/json-c?branch=master">Coveralls</a> <a href="https://coveralls.io/github/json-c/json-c?branch=master"><img src="https://coveralls.io/repos/github/json-c/json-c/badge.svg?branch=master" alt="Coverage Status" style="pointer-events: none;" class="inline"/></a></li>
  86. </ul>
  87. <p ><a class="anchor" id="installprereq"></a> </p>
  88. <h3><a class="anchor" id="autotoc_md4"></a>
  89. Prerequisites:</h3>
  90. <ul>
  91. <li><code>gcc</code>, <code>clang</code>, or another C compiler</li>
  92. <li><code>cmake&gt;=2.8</code>, <code>&gt;=3.16</code> recommended, <code>cmake=&gt;3.1</code> for tests</li>
  93. </ul>
  94. <p >To generate docs you'll also need:</p><ul>
  95. <li><code>doxygen&gt;=1.8.13</code></li>
  96. </ul>
  97. <p >If you are on a relatively modern system, you'll likely be able to install the prerequisites using your OS's packaging system.</p>
  98. <h3><a class="anchor" id="autotoc_md5"></a>
  99. Install using apt (e.g. Ubuntu 16.04.2 LTS)</h3>
  100. <pre class="fragment">sudo apt install git
  101. sudo apt install cmake
  102. sudo apt install doxygen # optional
  103. sudo apt install valgrind # optional
  104. </pre><p ><a class="anchor" id="buildcmds"></a> </p>
  105. <h3><a class="anchor" id="autotoc_md6"></a>
  106. Build instructions:</h3>
  107. <p ><code>json-c</code> GitHub repo: <a href="https://github.com/json-c/json-c">https://github.com/json-c/json-c</a></p>
  108. <pre class="fragment">$ git clone https://github.com/json-c/json-c.git
  109. $ mkdir json-c-build
  110. $ cd json-c-build
  111. $ cmake ../json-c # See CMake section below for custom arguments
  112. </pre><p >Note: it's also possible to put your build directory inside the json-c source directory, or even not use a separate build directory at all, but certain things might not work quite right (notably, <code>make distcheck</code>)</p>
  113. <p >Then:</p>
  114. <pre class="fragment">$ make
  115. $ make test
  116. $ make USE_VALGRIND=0 test # optionally skip using valgrind
  117. $ sudo make install # it could be necessary to execute make install
  118. </pre><h3><a class="anchor" id="autotoc_md7"></a>
  119. Generating documentation with Doxygen:</h3>
  120. <p >The library documentation can be generated directly from the source code using Doxygen tool:</p>
  121. <pre class="fragment"># in build directory
  122. make doc
  123. google-chrome doc/html/index.html
  124. </pre><p ><a class="anchor" id="CMake"></a> </p>
  125. <h2><a class="anchor" id="autotoc_md8"></a>
  126. CMake Options</h2>
  127. <p >The json-c library is built with <a href="https://cmake.org/cmake-tutorial/">CMake</a>, which can take a few options.</p>
  128. <table class="markdownTable">
  129. <tr class="markdownTableHead">
  130. <th class="markdownTableHeadNone">Variable </th><th class="markdownTableHeadNone">Type </th><th class="markdownTableHeadNone">Description </th></tr>
  131. <tr class="markdownTableRowOdd">
  132. <td class="markdownTableBodyNone">CMAKE_INSTALL_PREFIX </td><td class="markdownTableBodyNone">String </td><td class="markdownTableBodyNone">The install location. </td></tr>
  133. <tr class="markdownTableRowEven">
  134. <td class="markdownTableBodyNone">CMAKE_BUILD_TYPE </td><td class="markdownTableBodyNone">String </td><td class="markdownTableBodyNone">Defaults to "debug". </td></tr>
  135. <tr class="markdownTableRowOdd">
  136. <td class="markdownTableBodyNone">BUILD_SHARED_LIBS </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library only. </td></tr>
  137. <tr class="markdownTableRowEven">
  138. <td class="markdownTableBodyNone">BUILD_STATIC_LIBS </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">The default build generates a static (lib/a) library. Set this to OFF to create a shared library only. </td></tr>
  139. <tr class="markdownTableRowOdd">
  140. <td class="markdownTableBodyNone">DISABLE_STATIC_FPIC </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">The default builds position independent code. Set this to OFF to create a shared library only. </td></tr>
  141. <tr class="markdownTableRowEven">
  142. <td class="markdownTableBodyNone">DISABLE_BSYMBOLIC </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">Disable use of -Bsymbolic-functions. </td></tr>
  143. <tr class="markdownTableRowOdd">
  144. <td class="markdownTableBodyNone">DISABLE_THREAD_LOCAL_STORAGE </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">Disable use of Thread-Local Storage (HAVE___THREAD). </td></tr>
  145. <tr class="markdownTableRowEven">
  146. <td class="markdownTableBodyNone">DISABLE_WERROR </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">Disable use of -Werror. </td></tr>
  147. <tr class="markdownTableRowOdd">
  148. <td class="markdownTableBodyNone">DISABLE_EXTRA_LIBS </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">Disable use of extra libraries, libbsd </td></tr>
  149. <tr class="markdownTableRowEven">
  150. <td class="markdownTableBodyNone">DISABLE_JSON_POINTER </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">Omit json_pointer support from the build. </td></tr>
  151. <tr class="markdownTableRowOdd">
  152. <td class="markdownTableBodyNone">ENABLE_RDRAND </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">Enable RDRAND Hardware RNG Hash Seed. </td></tr>
  153. <tr class="markdownTableRowEven">
  154. <td class="markdownTableBodyNone">ENABLE_THREADING </td><td class="markdownTableBodyNone">Bool </td><td class="markdownTableBodyNone">Enable partial threading support. </td></tr>
  155. <tr class="markdownTableRowOdd">
  156. <td class="markdownTableBodyNone">OVERRIDE_GET_RANDOM_SEED </td><td class="markdownTableBodyNone">String </td><td class="markdownTableBodyNone">A block of code to use instead of the default implementation of json_c_get_random_seed(), e.g. on embedded platforms where not even the fallback to time() works. Must be a single line. </td></tr>
  157. </table>
  158. <p >Pass these options as <code>-D</code> on CMake's command-line.</p>
  159. <pre class="fragment"># build a static library only
  160. cmake -DBUILD_SHARED_LIBS=OFF ..
  161. </pre><h3><a class="anchor" id="autotoc_md9"></a>
  162. Building with partial threading support</h3>
  163. <p >Although json-c does not support fully multi-threaded access to object trees, it has some code to help make its use in threaded programs a bit safer. Currently, this is limited to using atomic operations for <a class="el" href="json__object_8h.html#ac5bbb5364ee14d645ac7b6e169a9d74b">json_object_get()</a> and <a class="el" href="json__object_8h.html#afabf61f932cd64a4122ca8092452eed5">json_object_put()</a>.</p>
  164. <p >Since this may have a performance impact, of at least 3x slower according to <a href="https://stackoverflow.com/a/11609063">https://stackoverflow.com/a/11609063</a>, it is disabled by default. You may turn it on by adjusting your cmake command with: -DENABLE_THREADING=ON</p>
  165. <p >Separately, the default hash function used for object field keys, lh_char_hash, uses a compare-and-swap operation to ensure the random seed is only generated once. Because this is a one-time operation, it is always compiled in when the compare-and-swap operation is available.</p>
  166. <h3><a class="anchor" id="autotoc_md10"></a>
  167. cmake-configure wrapper script</h3>
  168. <p >For those familiar with the old autoconf/autogen.sh/configure method, there is a <code>cmake-configure</code> wrapper script to ease the transition to cmake.</p>
  169. <pre class="fragment">mkdir build
  170. cd build
  171. ../cmake-configure --prefix=/some/install/path
  172. make
  173. </pre><p >cmake-configure can take a few options.</p>
  174. <table class="markdownTable">
  175. <tr class="markdownTableHead">
  176. <th class="markdownTableHeadNone">options </th><th class="markdownTableHeadNone">Description </th></tr>
  177. <tr class="markdownTableRowOdd">
  178. <td class="markdownTableBodyNone">prefix=PREFIX </td><td class="markdownTableBodyNone">install architecture-independent files in PREFIX </td></tr>
  179. <tr class="markdownTableRowEven">
  180. <td class="markdownTableBodyNone">enable-threading </td><td class="markdownTableBodyNone">Enable code to support partly multi-threaded use </td></tr>
  181. <tr class="markdownTableRowOdd">
  182. <td class="markdownTableBodyNone">enable-rdrand </td><td class="markdownTableBodyNone">Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms. </td></tr>
  183. <tr class="markdownTableRowEven">
  184. <td class="markdownTableBodyNone">enable-shared </td><td class="markdownTableBodyNone">build shared libraries [default=yes] </td></tr>
  185. <tr class="markdownTableRowOdd">
  186. <td class="markdownTableBodyNone">enable-static </td><td class="markdownTableBodyNone">build static libraries [default=yes] </td></tr>
  187. <tr class="markdownTableRowEven">
  188. <td class="markdownTableBodyNone">disable-Bsymbolic </td><td class="markdownTableBodyNone">Avoid linking with -Bsymbolic-function </td></tr>
  189. <tr class="markdownTableRowOdd">
  190. <td class="markdownTableBodyNone">disable-werror </td><td class="markdownTableBodyNone">Avoid treating compiler warnings as fatal errors </td></tr>
  191. </table>
  192. <p ><a class="anchor" id="testing"></a> </p>
  193. <h2><a class="anchor" id="autotoc_md11"></a>
  194. Testing:</h2>
  195. <p >By default, if valgrind is available running tests uses it. That can slow the tests down considerably, so to disable it use: </p><pre class="fragment">export USE_VALGRIND=0
  196. </pre><p >To run tests a separate build directory is recommended: </p><pre class="fragment">mkdir build-test
  197. cd build-test
  198. # VALGRIND=1 causes -DVALGRIND=1 to be passed when compiling code
  199. # which uses slightly slower, but valgrind-safe code.
  200. VALGRIND=1 cmake ..
  201. make
  202. make test
  203. # By default, if valgrind is available running tests uses it.
  204. make USE_VALGRIND=0 test # optionally skip using valgrind
  205. </pre><p >If a test fails, check <code>Testing/Temporary/LastTest.log</code>, <code>tests/testSubDir/${testname}/${testname}.vg.out</code>, and other similar files. If there is insufficient output try: </p><pre class="fragment">VERBOSE=1 CTEST_OUTPUT_ON_FAILURE=1 make test
  206. </pre><p> or </p><pre class="fragment">JSONC_TEST_TRACE=1 make test
  207. </pre><p> and check the log files again.</p>
  208. <p ><a class="anchor" id="buildvcpkg"></a> </p>
  209. <h2><a class="anchor" id="autotoc_md12"></a>
  210. Building on Unix and Windows with &lt;tt&gt;vcpkg&lt;/tt&gt;</h2>
  211. <p >You can download and install JSON-C using the <a href="https://github.com/Microsoft/vcpkg/">vcpkg</a> dependency manager: </p><pre class="fragment">git clone https://github.com/Microsoft/vcpkg.git
  212. cd vcpkg
  213. ./bootstrap-vcpkg.sh
  214. ./vcpkg integrate install
  215. vcpkg install json-c
  216. </pre><p> The JSON-C port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please <a href="https://github.com/Microsoft/vcpkg">create an issue or pull request</a> on the vcpkg repository.</p>
  217. <p ><a class="anchor" id="android"></a> </p>
  218. <h2><a class="anchor" id="autotoc_md13"></a>
  219. Building for Android</h2>
  220. <p >Building on Android is now particularly well supported, but there have been some reports of success using <a href="https://developer.android.com/ndk/guides/cmake">https://developer.android.com/ndk/guides/cmake</a></p>
  221. <pre class="fragment">mkdir json-c-build
  222. cd json-c-build/
  223. export NDK_HOME=~/Library/Android/sdk/ndk/22.1.7171670/
  224. cmake \
  225. --toolchain=$NDK_HOME/build/cmake/android.toolchain.cmake \
  226. -DANDROID_STL=none \
  227. -DANDROID_ABI=arm64-v8a \
  228. -DANDROID_PLATFORM=android-29 \
  229. -DANDROID_LD=lld \
  230. -DCMAKE_BUILD_TYPE=MinSizeRel \
  231. -DCMAKE_INSTALL_PREFIX=&lt;install prefix&gt; \
  232. -DENABLE_THREADING=true \
  233. ..
  234. make install
  235. </pre><p ><a class="anchor" id="linking"></a> </p>
  236. <h2><a class="anchor" id="autotoc_md14"></a>
  237. Linking to &lt;tt&gt;libjson-c&lt;/tt&gt;</h2>
  238. <p >If your system has <code>pkgconfig</code>, then you can just add this to your <code>makefile</code>:</p>
  239. <pre class="fragment">CFLAGS += $(shell pkg-config --cflags json-c)
  240. LDFLAGS += $(shell pkg-config --libs json-c)
  241. </pre><p >Without <code>pkgconfig</code>, you might do something like this:</p>
  242. <pre class="fragment">JSON_C_DIR=/path/to/json_c/install
  243. CFLAGS += -I$(JSON_C_DIR)/include/json-c
  244. # Or to use lines like: #include &lt;json-c/json_object.h&gt;
  245. #CFLAGS += -I$(JSON_C_DIR)/include
  246. LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
  247. </pre><p >If your project uses cmake:</p>
  248. <ul>
  249. <li>Add to your CMakeLists.txt file:</li>
  250. </ul>
  251. <pre class="fragment">find_package(json-c CONFIG)
  252. target_link_libraries(${PROJECT_NAME} PRIVATE json-c::json-c)
  253. </pre><ul>
  254. <li>Then you might run in your project:</li>
  255. </ul>
  256. <pre class="fragment">cd build
  257. cmake -DCMAKE_PREFIX_PATH=/path/to/json_c/install/lib64/cmake ..
  258. </pre><p ><a class="anchor" id="using"></a> </p>
  259. <h2><a class="anchor" id="autotoc_md15"></a>
  260. Using json-c</h2>
  261. <p >To use json-c you can either include <a class="el" href="json_8h.html" title="A convenience header that may be included instead of other individual ones.">json.h</a>, or preferably, one of the following more specific header files:</p>
  262. <ul>
  263. <li><a class="el" href="json__object_8h.html" title="Core json-c API. Start here, or with json_tokener.h.">json_object.h</a> - Core types and methods.</li>
  264. <li><a class="el" href="json__tokener_8h.html" title="Methods to parse an input string into a tree of json_object objects.">json_tokener.h</a> - Methods for parsing and serializing json-c object trees.</li>
  265. <li><a class="el" href="json__pointer_8h.html" title="JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree.">json_pointer.h</a> - JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree.</li>
  266. <li><a class="el" href="json__object__iterator_8h.html" title="An API for iterating over json_type_object objects, styled to be familiar to C++ programmers....">json_object_iterator.h</a> - Methods for iterating over single json_object instances. (See also <code><a class="el" href="json__object_8h.html#acf5f514a9e0061c10fc08055762639ee">json_object_object_foreach()</a></code> in <a class="el" href="json__object_8h.html" title="Core json-c API. Start here, or with json_tokener.h.">json_object.h</a>)</li>
  267. <li><a class="el" href="json__visit_8h.html" title="Methods for walking a tree of objects.">json_visit.h</a> - Methods for walking a tree of json-c objects.</li>
  268. <li><a class="el" href="json__util_8h.html" title="Miscllaneous utility functions and macros.">json_util.h</a> - Miscellaneous utility functions.</li>
  269. </ul>
  270. <p >For a full list of headers see <a href="https://json-c.github.io/json-c/json-c-current-release/doc/html/files.html">files.html</a></p>
  271. <p >The primary type in json-c is json_object. It describes a reference counted tree of json objects which are created by either parsing text with a <a class="el" href="structjson__tokener.html">json_tokener</a> (i.e. <code><a class="el" href="json__tokener_8h.html#a6d39fd40a8720a1b96d9e0d8fea4afab">json_tokener_parse_ex()</a></code>), or by creating (with <code><a class="el" href="json__object_8h.html#a514cf1a819b82dba0c1236695cdedd1e">json_object_new_object()</a></code>, <code><a class="el" href="json__object_8h.html#a1a948f2bb24d91408212c12c2791dcaa">json_object_new_int()</a></code>, etc...) and adding (with <code><a class="el" href="json__object_8h.html#a27bd808a022251059a43f1f6370441cd">json_object_object_add()</a></code>, <code><a class="el" href="json__object_8h.html#a18cdd9a7455e09f36cdf6e5756b7f586">json_object_array_add()</a></code>, etc...) them individually. Typically, every object in the tree will have one reference, from its parent. When you are done with the tree of objects, you call <a class="el" href="json__object_8h.html#afabf61f932cd64a4122ca8092452eed5">json_object_put()</a> on just the root object to free it, which recurses down through any child objects calling <a class="el" href="json__object_8h.html#afabf61f932cd64a4122ca8092452eed5">json_object_put()</a> on each one of those in turn.</p>
  272. <p >You can get a reference to a single child (<code><a class="el" href="json__object_8h.html#af7a569d69c3b90e79af7ef21e557e402">json_object_object_get()</a></code> or <code><a class="el" href="json__object_8h.html#af229a1625af2aae7116a0bd6fb1e5ad2">json_object_array_get_idx()</a></code>) and use that object as long as its parent is valid. <br />
  273. If you need a child object to live longer than its parent, you can increment the child's refcount (<code><a class="el" href="json__object_8h.html#ac5bbb5364ee14d645ac7b6e169a9d74b">json_object_get()</a></code>) to allow it to survive the parent being freed or it being removed from its parent (<code><a class="el" href="json__object_8h.html#ac6605fdafca20bd5d33c84f4f80a3bda">json_object_object_del()</a></code> or <code><a class="el" href="json__object_8h.html#a722eca9f578704d3af38b97549242c1f">json_object_array_del_idx()</a></code>)</p>
  274. <p >When parsing text, the <a class="el" href="structjson__tokener.html">json_tokener</a> object is independent from the json_object that it returns. It can be allocated (<code><a class="el" href="json__tokener_8h.html#aa9ccdfe720ac77f7cbe0951c778b99d1">json_tokener_new()</a></code>) used one or multiple times (<code><a class="el" href="json__tokener_8h.html#a6d39fd40a8720a1b96d9e0d8fea4afab">json_tokener_parse_ex()</a></code>, and freed (<code><a class="el" href="json__tokener_8h.html#a887c4661906fc6b36cc366304e522534">json_tokener_free()</a></code>) while the json_object objects live on.</p>
  275. <p >A json_object tree can be serialized back into a string with <code><a class="el" href="json__object_8h.html#a47fe3e7980dc81a1d7f2ab303870789e">json_object_to_json_string_ext()</a></code>. The string that is returned is only valid until the next "to_json_string" call on that same object. Also, it is freed when the json_object is freed. </p>
  276. </div></div><!-- PageDoc -->
  277. </div><!-- contents -->
  278. <!-- start footer part -->
  279. <hr class="footer"/><address class="footer"><small>
  280. Generated on Sun Sep 15 2024 16:22:28 for json-c by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
  281. </small></address>
  282. </body>
  283. </html>