https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/
C M4 Shell Makefile CMake C++
Clone or download
hawicz Merge pull request #431 from LeSpocky/cmake
cmake: Bump required version
Latest commit 2327b23 Jul 12, 2018
Permalink
Failed to load latest commit information.
autoconf-archive Fix a few places that needed adjustment for the size_t changes, inclu… May 23, 2016
fuzz pull in fuzzers, add CI scripts later Feb 6, 2018
tests Fixed typos Apr 24, 2018
.editorconfig Adding a file for EditorConfig Aug 12, 2016
.gitignore Merge branch 'json_deep_copy' of https://github.com/commodo/json-c in… Nov 29, 2017
.travis.yml build,travis: drop `-enable-strerror-override` argument (no longer ex… Jul 19, 2017
AUTHORS Add Jehiah and myself to the list of authors. Jun 14, 2011
Android.configure.mk Issue #369: note some useful settings when building for Android. Oct 20, 2017
CMakeLists.txt cmake: Bump required version Jul 12, 2018
COPYING Add my copyright. Jul 30, 2012
ChangeLog Update the change log for the 0.13.1 release. Mar 6, 2018
Doxyfile doc: Use other doxygen feature to specify mainpage Dec 11, 2017
INSTALL Issue #308: improve the build instructions in README.md to include th… Jul 9, 2017
Makefile.am Bump the major version of the .so library generated up to 4.0 to avoi… Jan 16, 2018
NEWS Improving README Aug 8, 2016
README Improving README Aug 8, 2016
README.html Remove out of date win32 build information, and mention the need to u… Oct 23, 2017
README.md doc: Use other doxygen feature to specify mainpage Dec 11, 2017
RELEASE_CHECKLIST.txt Drop mention of README-WIN32.html in the release checklist. Dec 9, 2017
STYLE.txt Fixed typos Apr 24, 2018
appveyor.yml Try the appveyor changes again, using %Configuration% instead of "Debug" May 27, 2018
arraylist.c arraylist: Fix names of parameters for callback function Jun 1, 2018
arraylist.h arraylist: Fix names of parameters for callback function Jun 1, 2018
autogen.sh Use AC_CONFIG_MACRO_DIRS to specify path to the ax macros instead of … Sep 4, 2017
config.h.win32 Update the master branch to version 0.13.99 Dec 9, 2017
configure.ac Issue #396: check for toolchain compatibilty with _REENTRANT before a… Mar 5, 2018
debug.c Remove trailing whitespace Aug 26, 2014
debug.h Add a brief overview of each file to the docs. Dec 6, 2017
issues_closed_for_0.13.md Add a couple more issues to the list of those closed for 0.13 Dec 5, 2017
json-c-uninstalled.pc.in Re-add the "json" pkg-config file as a compatibility shim. Jul 29, 2012
json-c.pc.in Very minor changes not related to C source code Aug 8, 2016
json.h Add a brief overview of each file to the docs. Dec 6, 2017
json_c_version.c Add a json_c_version.h header (included from json.h), and several mac… Dec 23, 2012
json_c_version.h Update the master branch to version 0.13.99 Dec 9, 2017
json_config.h.in Include json_inttypes.h in json_object.h since we use types like int3… Feb 16, 2012
json_config.h.win32 Updated config for vs2010/winsdk71 as well as vs2013 Mar 4, 2015
json_inttypes.h Add a brief overview of each file to the docs. Dec 6, 2017
json_object.c Issue #407: fix incorrect casts in calls to ctype functions (isdigit … Mar 25, 2018
json_object.h Issue #419: document that NULL may be passed to json_object_put(). Jun 13, 2018
json_object_iterator.c Adjust the description of json_object_iterator a bit. Dec 5, 2017
json_object_iterator.h Adjust the description of json_object_iterator a bit. Dec 5, 2017
json_object_private.h json_object_private: Use unsigned 32-bit integer type for refcount Dec 17, 2017
json_pointer.c Fixed typos Apr 24, 2018
json_pointer.h Add a brief overview of each file to the docs. Dec 6, 2017
json_tokener.c Issue #407: fix incorrect casts in calls to ctype functions (isdigit … Mar 25, 2018
json_tokener.h Add a brief overview of each file to the docs. Dec 6, 2017
json_util.c Rename _set_last_err() to _json_c_set_last_err(). Nov 29, 2017
json_util.h Issue #418: Fix docs for json_util_from_fd and json_util_from_file to… Jun 15, 2018
json_visit.c Make sure to include the "*" on function pointer arguments to avoid a… Dec 4, 2017
json_visit.h Add a brief overview of each file to the docs. Dec 6, 2017
libjson.c Remove trailing whitespace Aug 26, 2014
linkhash.c Remove the TRUE and FALSE defines. Dec 23, 2017
linkhash.h Remove the previously deprecated lh_table_lookup() function, in favor… Dec 10, 2017
math_compat.h Add a brief overview of each file to the docs. Dec 6, 2017
printbuf.c PR#331: for Visual Studio, use a snprintf/vsnprintf wrapper that ensu… Aug 25, 2017
printbuf.h Undeprecate the array_list, lh_table and printbuf typedefs, but move … Dec 7, 2017
random_seed.c 1.make it can been compiled with Visual Studio 2010 Aug 22, 2017
random_seed.h Add a brief overview of each file to the docs. Dec 6, 2017
snprintf_compat.h Add a brief overview of each file to the docs. Dec 6, 2017
strdup_compat.h Add a brief overview of each file to the docs. Dec 6, 2017
strerror_override.c PR #336: Fix typo in defining STRERROR_OVERRIDE_IMPL Jul 28, 2017
strerror_override.h Add a brief overview of each file to the docs. Dec 6, 2017
strerror_override_private.h Add a brief overview of each file to the docs. Dec 6, 2017
vasprintf_compat.h Add a brief overview of each file to the docs. Dec 6, 2017

README.md

json-c

  1. Overview and Build Status
  2. Building on Unix
  3. Install Prerequisites
  4. Building with partial threading support
  5. Linking to libjson-c
  6. Using json-c

JSON-C - A JSON implementation in C

Build Status

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 RFC 7159.

Building on Unix with git, gcc and autotools

Home page for json-c: https://github.com/json-c/json-c/wiki

Prerequisites:

See also the "Installing prerequisites" section below.

  • gcc, clang, or another C compiler
  • libtool>=2.2.6b

If you're not using a release tarball, you'll also need:

  • autoconf>=2.64 (autoreconf)
  • automake>=1.13

Make sure you have a complete libtool install, including libtoolize.

To generate docs (e.g. as part of make distcheck) you'll also need:

  • doxygen>=1.8.13

Build instructions:

json-c GitHub repo: https://github.com/json-c/json-c

$ git clone https://github.com/json-c/json-c.git
$ cd json-c
$ sh autogen.sh

followed by

$ ./configure  # --enable-threading
$ make
$ make install

To build and run the test programs:

$ make check
$ make USE_VALGRIND=0 check   # optionally skip using valgrind

Install prerequisites

If you are on a relatively modern system, you'll likely be able to install the prerequisites using your OS's packaging system.

Install using apt (e.g. Ubuntu 16.04.2 LTS)

sudo apt install git
sudo apt install autoconf automake libtool
sudo apt install valgrind # optional

Then start from the "git clone" command, above.

Manually install and build autoconf, automake and libtool

For older OS's that don't have up-to-date version of the packages will require a bit more work. For example, CentOS release 5.11, etc...

curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
curl -O http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
curl -O http://ftp.gnu.org/gnu/libtool/libtool-2.2.6b.tar.gz

tar xzf autoconf-2.69.tar.gz
tar xzf automake-1.15.tar.gz
tar xzf libtool-2.2.6b.tar.gz

export PATH=${HOME}/ac_install/bin:$PATH

(cd autoconf-2.69 && \
  ./configure --prefix ${HOME}/ac_install && \
  make && \
  make install)

(cd automake-1.15 && \
  ./configure --prefix ${HOME}/ac_install && \
  make && \
  make install)

(cd libtool-2.2.6b && \
  ./configure --prefix ${HOME}/ac_install && \
  make && \
  make install)

Building with partial threading support

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 json_object_get() and json_object_put().

Since this may have a performance impact, of at least 3x slower according to https://stackoverflow.com/a/11609063, it is disabled by default. You may turn it on by adjusting your configure command with: --enable-threading

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.

Linking to libjson-c

If your system has pkgconfig, then you can just add this to your makefile:

CFLAGS += $(shell pkg-config --cflags json-c)
LDFLAGS += $(shell pkg-config --libs json-c)

Without pkgconfig, you would do something like this:

JSON_C_DIR=/path/to/json_c/install
CFLAGS += -I$(JSON_C_DIR)/include/json-c
LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c

Using json-c

To use json-c you can either include json.h, or preferrably, one of the following more specific header files:

  • json_object.h - Core types and methods.
  • json_tokener.h - Methods for parsing and serializing json-c object trees.
  • json_pointer.h - JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree.
  • json_object_iterator.h - Methods for iterating over single json_object instances.
  • json_visit.h - Methods for walking a tree of json-c objects.
  • json_util.h - Miscelleanous utility functions.

For a full list of headers see files.html