|
- <!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"/>
- <title>json-c: `json-c`</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="doxygen.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td style="padding-left: 0.5em;">
- <div id="projectname">json-c
-  <span id="projectnumber">0.14</span>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.2 -->
- <div id="navrow1" class="tabs">
- <ul class="tablist">
- <li><a href="index.html"><span>Main Page</span></a></li>
- <li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
- <li><a href="annotated.html"><span>Data Structures</span></a></li>
- <li><a href="files.html"><span>Files</span></a></li>
- </ul>
- </div>
- </div><!-- top -->
- <div class="header">
- <div class="headertitle">
- <div class="title">`json-c` </div> </div>
- </div><!--header-->
- <div class="contents">
- <div class="textblock"><ol type="1">
- <li><a href="#overview">Overview and Build Status</a></li>
- <li><a href="#buildunix">Building on Unix</a><ul>
- <li><a href="#installprereq">Prerequisites</a></li>
- <li><a href="#buildcmds">Build commands</a></li>
- </ul>
- </li>
- <li><a href="#CMake">CMake options</a></li>
- <li><a href="#testing">Testing</a></li>
- <li><a href="#buildvcpkg">Building with `vcpkg`</a></li>
- <li><a href="#linking">Linking to libjson-c</a></li>
- <li><a href="#using">Using json-c</a></li>
- </ol>
- <h2>JSON-C - A JSON implementation in C <a class="anchor" id="overview"></a></h2>
- <p>Build Status</p>
- <ul>
- <li><a href="https://ci.appveyor.com/project/hawicz/json-c">AppVeyor Build</a> <div class="image">
- <img src="https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true" alt="AppVeyor Build Status"/>
- </div>
- </li>
- <li><a href="https://travis-ci.org/json-c/json-c">Travis Build</a> <div class="image">
- <img src="https://travis-ci.org/json-c/json-c.svg?branch=master" alt="Travis Build Status"/>
- </div>
- </li>
- </ul>
- <p>Test Status</p>
- <ul>
- <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"></a></li>
- </ul>
- <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://tools.ietf.org/html/rfc7159">RFC 7159</a>.</p>
- <h2>Building on Unix with <code>git</code>, <code>gcc</code> and <code>cmake</code> <a class="anchor" id="buildunix"></a></h2>
- <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>
- <h3>Prerequisites: <a class="anchor" id="installprereq"></a></h3>
- <ul>
- <li><code>gcc</code>, <code>clang</code>, or another C compiler</li>
- </ul>
- <ul>
- <li>cmake>=2.8, >=3.16 recommended</li>
- </ul>
- <p>To generate docs you'll also need:</p>
- <ul>
- <li><code>doxygen>=1.8.13</code></li>
- </ul>
- <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>
- <h3>Install using apt (e.g. Ubuntu 16.04.2 LTS)</h3>
- <p>```sh sudo apt install git sudo apt install cmake sudo apt install doxygen # optional sudo apt install valgrind # optional ```</p>
- <h3>Build instructions: <a class="anchor" id="buildcmds"></a></h3>
- <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>
- <p>```sh $ git clone <a href="https://github.com/json-c/json-c.git">https://github.com/json-c/json-c.git</a> $ mkdir json-c-build $ cd json-c-build $ cmake ../json-c # See CMake section below for custom arguments ```</p>
- <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>
- <p>Then:</p>
- <p>```sh $ make $ make test $ make USE_VALGRIND=0 test # optionally skip using valgrind $ make install ```</p>
- <h3>Generating documentation with Doxygen:</h3>
- <p>The libray documentation can be generated directly from the source codes using Doxygen tool:</p>
- <p>```sh </p>
- <h1>in build directory</h1>
- <p>make doc google-chrome doc/html/index.html ```</p>
- <h2>CMake Options <a class="anchor" id="CMake"></a></h2>
- <p>The json-c library is built with <a href="https://cmake.org/cmake-tutorial/">CMake</a>, which can take a few options.</p>
- <table class="doxtable">
- <tr>
- <th>Variable </th><th>Type </th><th>Description</th></tr>
- <tr>
- <td>CMAKE_INSTALL_PREFIX </td><td>String </td><td>The install location. </td></tr>
- <tr>
- <td>CMAKE_BUILD_TYPE </td><td>String </td><td>Defaults to "debug" </td></tr>
- <tr>
- <td>BUILD_SHARED_LIBS </td><td>Bool </td><td>The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library instead. </td></tr>
- <tr>
- <td>ENABLE_RDRAND </td><td>Bool </td><td>Enable RDRAND Hardware RNG Hash Seed </td></tr>
- <tr>
- <td>ENABLE_THREADING </td><td>Bool </td><td>Enable partial threading support </td></tr>
- <tr>
- <td>DISABLE_WERROR </td><td>Bool </td><td>Disable use of -Werror </td></tr>
- <tr>
- <td>DISABLE_BSYMBOLIC </td><td>Bool </td><td>Disable use of -Bsymbolic-functions </td></tr>
- </table>
- <p>Pass these options as <code>-D</code> on CMake's command-line.</p>
- <p>```sh cmake -DBUILD_SHARED_LIBS=OFF ... ```</p>
- <h3>Building with partial threading support</h3>
- <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#a675aa3a9cced685dbfd1c1a770a0c3e4">json_object_get()</a> and <a class="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 <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>
- <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>
- <h3>cmake-configure wrapper script</h3>
- <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>
- <p>```sh mkdir build cd build ../cmake-configure –prefix=/some/install/path make ```</p>
- <p>cmake-configure can take a few options.</p>
- <table class="doxtable">
- <tr>
- <th>options </th><th>Description</th></tr>
- <tr>
- <td>prefix=PREFIX </td><td>install architecture-independent files in PREFIX </td></tr>
- <tr>
- <td>enable-threading </td><td>Enable code to support partly multi-threaded use </td></tr>
- <tr>
- <td>enable-rdrand </td><td>Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms. </td></tr>
- <tr>
- <td>enable-shared </td><td>build shared libraries [default=yes] </td></tr>
- <tr>
- <td>enable-static </td><td>build static libraries [default=yes] </td></tr>
- <tr>
- <td>disable-Bsymbolic </td><td>Avoid linking with -Bsymbolic-function </td></tr>
- <tr>
- <td>disable-werror </td><td>Avoid treating compiler warnings as fatal errors </td></tr>
- </table>
- <h2>Testing: <a class="anchor" id="testing"></a></h2>
- <p>By default, if valgrind is available running tests uses it. That can slow the tests down considerably, so to disable it use: ```sh export USE_VALGRIND=0 ```</p>
- <p>To run tests a separate build directory is recommended: ```sh mkdir build-test cd build-test </p>
- <h1>VALGRIND=1 causes -DVALGRIND=1 to be passed when compiling code</h1>
- <h1>which uses slightly slower, but valgrind-safe code.</h1>
- <p>VALGRIND=1 cmake .. make</p>
- <p>make test </p>
- <h1>By default, if valgrind is available running tests uses it.</h1>
- <p>make USE_VALGRIND=0 test # optionally skip using valgrind ```</p>
- <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: ```sh VERBOSE=1 make test ``` or ```sh JSONC_TEST_TRACE=1 make test ``` and check the log files again.</p>
- <h2>Building on Unix and Windows with <code>vcpkg</code> <a class="anchor" id="buildvcpkg"></a></h2>
- <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
- cd vcpkg
- ./bootstrap-vcpkg.sh
- ./vcpkg integrate install
- vcpkg install json-c
- </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>
- <h2>Linking to <code>libjson-c</code> <a class="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>```make CFLAGS += $(shell pkg-config –cflags json-c) LDFLAGS += $(shell pkg-config –libs json-c) ```</p>
- <p>Without <code>pkgconfig</code>, you would do something like this:</p>
- <p>```make JSON_C_DIR=/path/to/json_c/install CFLAGS += -I/include/json-c LDFLAGS+= -L/lib -ljson-c ```</p>
- <h2>Using json-c <a class="anchor" id="using"></a></h2>
- <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 preferrably, one of the following more specific header files:</p>
- <ul>
- <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>
- <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>
- <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>
- <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. 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 <a class="el" href="structjson__object.html">json_object</a> instances.</li>
- <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>
- <li><a class="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 <a href="http://json-c.github.io/json-c/json-c-0.13.1/doc/html/files.html">files.html</a> </p>
- </div></div><!-- contents -->
- <!-- start footer part -->
- <hr class="footer"/><address class="footer"><small>
- Generated on Sun Apr 19 2020 03:40:44 for json-c by  <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/>
- </a> 1.8.2
- </small></address>
- </body>
- </html>
|