<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 <ahref="https://tools.ietf.org/html/rfc7159">RFC 7159</a>.</p>
<h2>Building on Unix with <code>git</code>, <code>gcc</code> and <code>autotools</code><aclass="anchor"id="buildunix"></a></h2>
<p>Home page for json-c: <ahref="https://github.com/json-c/json-c/wiki">https://github.com/json-c/json-c/wiki</a></p>
<h3>Prerequisites:</h3>
<p>See also the "Installing prerequisites" section below.</p>
<ul>
<li><code>gcc</code>, <code>clang</code>, or another C compiler</li>
<li><code>libtool>=2.2.6b</code></li>
</ul>
<p>If you're not using a release tarball, you'll also need:</p>
<p>Although json-c does not support fully multi-threaded access to object trees, it has some code to help make use in threaded programs a bit safer. Currently, this is limited to using atomic operations for <aclass="el"href="json__object_8h.html#a675aa3a9cced685dbfd1c1a770a0c3e4">json_object_get()</a> and <aclass="el"href="json__object_8h.html#afabf61f932cd64a4122ca8092452eed5">json_object_put()</a>.</p>
<p>Since this may have a performance impact, of at least 3x slower according to <ahref="https://stackoverflow.com/a/11609063,">https://stackoverflow.com/a/11609063,</a> it is disabled by default. You may turn it on by adjusting your configure command with: –enable-threading</p>
<p>Separately, the default hash function used for object field keys, lh_char_hash, uses a compare-and-swap operation to ensure the randomly 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>
<h2>Linking to <code>libjson-c</code><aclass="anchor"id="linking"></a></h2>
<p>If your system has <code>pkgconfig</code>, then you can just add this to your <code>makefile</code>:</p>
<p>To use json-c you can either include <aclass="el"href="json_8h.html"title="A convenience header that may be included instead of other individual ones. ">json.h</a>, or preferrably, one of the following more specific header files:</p>
<ul>
<li><aclass="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>
<li><aclass="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>
<li><aclass="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>
<li><aclass="el"href="json__object__iterator_8h.html"title="An API for iterating over json_type_object objects, styled to be familiar to C++ programmers. Unlike json_object_object_foreach() and json_object_object_foreachC(), this avoids the need to expose json-c internals like lh_entry. ">json_object_iterator.h</a> - Methods for iterating over single <aclass="el"href="structjson__object.html">json_object</a> instances.</li>
<li><aclass="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>
<li><aclass="el"href="json__util_8h.html"title="Miscllaneous utility functions and macros. ">json_util.h</a> - Miscelleanous utility functions.</li>
</ul>
<p>For a full list of headers see <ahref="files.html">files.html</a></p>