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.

README.md 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. `json-c` {#mainpage}
  2. ========
  3. 1. [Overview and Build Status](#overview)
  4. 2. [Building on Unix](#buildunix)
  5. 3. [Install Prerequisites](#installprereq)
  6. 4. [Building with partial threading support](#buildthreaded)
  7. 5. [Linking to libjson-c](#linking)
  8. 6. [Using json-c](#using)
  9. JSON-C - A JSON implementation in C <a name="overview"></a>
  10. -----------------------------------
  11. Build Status
  12. * [AppVeyor Build](https://ci.appveyor.com/project/hawicz/json-c) ![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true)
  13. * [Travis Build](https://travis-ci.org/json-c/json-c) ![Travis Build Status](https://travis-ci.org/json-c/json-c.svg?branch=master)
  14. JSON-C implements a reference counting object model that allows you to easily
  15. construct JSON objects in C, output them as JSON formatted strings and parse
  16. JSON formatted strings back into the C representation of JSON objects.
  17. It aims to conform to [RFC 7159](https://tools.ietf.org/html/rfc7159).
  18. Building on Unix with `git`, `gcc` and `autotools` <a name="buildunix"></a>
  19. --------------------------------------------------
  20. Home page for json-c: https://github.com/json-c/json-c/wiki
  21. ### Prerequisites:
  22. See also the "Installing prerequisites" section below.
  23. - `gcc`, `clang`, or another C compiler
  24. - `libtool>=2.2.6b`
  25. If you're not using a release tarball, you'll also need:
  26. - `autoconf>=2.64` (`autoreconf`)
  27. - `automake>=1.13`
  28. Make sure you have a complete `libtool` install, including `libtoolize`.
  29. To generate docs (e.g. as part of make distcheck) you'll also need:
  30. - `doxygen>=1.8.13`
  31. ### Build instructions:
  32. `json-c` GitHub repo: https://github.com/json-c/json-c
  33. ```sh
  34. $ git clone https://github.com/json-c/json-c.git
  35. $ cd json-c
  36. $ sh autogen.sh
  37. ```
  38. followed by
  39. ```sh
  40. $ ./configure # --enable-threading
  41. $ make
  42. $ make install
  43. ```
  44. To build and run the test programs:
  45. ```sh
  46. $ make check
  47. $ make USE_VALGRIND=0 check # optionally skip using valgrind
  48. ```
  49. Install prerequisites <a name="installprereq"></a>
  50. -----------------------
  51. If you are on a relatively modern system, you'll likely be able to install
  52. the prerequisites using your OS's packaging system.
  53. ### Install using apt (e.g. Ubuntu 16.04.2 LTS)
  54. ```sh
  55. sudo apt install git
  56. sudo apt install autoconf automake libtool
  57. sudo apt install valgrind # optional
  58. ```
  59. Then start from the "git clone" command, above.
  60. ### Manually install and build autoconf, automake and libtool
  61. For older OS's that don't have up-to-date version of the packages will
  62. require a bit more work. For example, CentOS release 5.11, etc...
  63. ```sh
  64. curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
  65. curl -O http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
  66. curl -O http://ftp.gnu.org/gnu/libtool/libtool-2.2.6b.tar.gz
  67. tar xzf autoconf-2.69.tar.gz
  68. tar xzf automake-1.15.tar.gz
  69. tar xzf libtool-2.2.6b.tar.gz
  70. export PATH=${HOME}/ac_install/bin:$PATH
  71. (cd autoconf-2.69 && \
  72. ./configure --prefix ${HOME}/ac_install && \
  73. make && \
  74. make install)
  75. (cd automake-1.15 && \
  76. ./configure --prefix ${HOME}/ac_install && \
  77. make && \
  78. make install)
  79. (cd libtool-2.2.6b && \
  80. ./configure --prefix ${HOME}/ac_install && \
  81. make && \
  82. make install)
  83. ```
  84. Building with partial threading support <a name="buildthreaded"></a>
  85. ----------------------------------------
  86. Although json-c does not support fully multi-threaded access to
  87. object trees, it has some code to help make use in threaded programs
  88. a bit safer. Currently, this is limited to using atomic operations for
  89. json_object_get() and json_object_put().
  90. Since this may have a performance impact, of at least 3x slower
  91. according to https://stackoverflow.com/a/11609063, it is disabled by
  92. default. You may turn it on by adjusting your configure command with:
  93. --enable-threading
  94. Separately, the default hash function used for object field keys,
  95. lh_char_hash, uses a compare-and-swap operation to ensure the randomly
  96. seed is only generated once. Because this is a one-time operation, it
  97. is always compiled in when the compare-and-swap operation is available.
  98. Linking to `libjson-c` <a name="linking">
  99. ----------------------
  100. If your system has `pkgconfig`,
  101. then you can just add this to your `makefile`:
  102. ```make
  103. CFLAGS += $(shell pkg-config --cflags json-c)
  104. LDFLAGS += $(shell pkg-config --libs json-c)
  105. ```
  106. Without `pkgconfig`, you would do something like this:
  107. ```make
  108. JSON_C_DIR=/path/to/json_c/install
  109. CFLAGS += -I$(JSON_C_DIR)/include/json-c
  110. LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
  111. ```
  112. Using json-c <a name="using">
  113. ------------
  114. To use json-c you can either include json.h, or preferrably, one of the
  115. following more specific header files:
  116. * json_object.h - Core types and methods.
  117. * json_tokener.h - Methods for parsing and serializing json-c object trees.
  118. * json_pointer.h - JSON Pointer (RFC 6901) implementation for retrieving
  119. objects from a json-c object tree.
  120. * json_object_iterator.h - Methods for iterating over single json_object instances.
  121. * json_visit.h - Methods for walking a tree of json-c objects.
  122. * json_util.h - Miscelleanous utility functions.
  123. For a full list of headers see [files.html](files.html)