###### 各种 JSON 解析库的功能简介

===================================
william/libjson
Last Update：2013-09-27
description

json.c is a JSON C library that supports path autovivification and conversion. Autovivified and converted paths greatly simplify manipulation of JSON trees, allowing one to discard most bothersome boilerplate code.
json.c 作为 JSON 的 C 库实现，支持 path autovivification 和 conversion 功能。这两项功能极大的简化了针对 JSON 树结构上的各种操作，允许你在代码编写过程中避免大量让人讨厌的“样板”代码。

Because "JSON schema" is something of an oxymoron, the library makes the presumption that you mean what you say; that the schema is whatever the code does. If you attempt to write through a non-existent or type-incompatible path, the library fixes the tree to accomodate the request, rather than punt back to the caller. Likewise, a read through a non-existent or type-incompatible path returns a sane, default value—specifically 0 or an empty string.

In addition, a stack interface allows changing the current root. This makes descending up and down the tree more convenient, and eases abstraction as code which reads or writes subtrees need not be concerned with the path to that particular subtree.

Both the parser and composer are restartable and operate over a series of caller provided input and output buffers. This is intended to ease integration with networked I/O environments, particularly non-blocking environments. JSON data can be both parsed and composed byte-by-byte without any intermediate, internal buffers. No callback schemes are used as half measures, so the user code needn't arbitrarily split blocks of code between different halves of a parse or compose operation.

json.c is implemented in a single source file, along with a companion header which defines the API. The only dependency is llrb.h.

usage

The API is broken up into three main sections. The grouping of declarations in the header reflects this, and makes for relatively easy perusal.
API 主要分成 3 个主要部分。可以从头文件中的分组声明看出。

The core API consists of routines to construct a JSON context object, and to parse and compose JSON data.

The second set consists of routines to manipulate JSON value objects directly, although this is mostly used internally.

The third consists of routines which access and manipulate the JSON tree through a path expression. Objects are accessed with a dot ("."), arrays indexed by square brackets ("[", "]"). String interpolation is accomplished using the special character "$" and index interpolation using "#", along with their respective arguments (char pointer or int) in the passed variable argument list. The syntax uses the standard backslash escaping protocol. 第三部分包括：通过路径表达式访问和操作 JSON 树结构的 API。object 的访问通过点操作符（“.”）；array 的索引通过中括号实现（“[”,“]”）；字符串内的插值操作使用特殊字符“$”；array 索引的插值操作使用特殊字符“#”。最后两个插值操作需要同时提供相应的参数列表（字符串指针或者整形变量）。整体的语法规则使用了标准的反斜杠转义协议。

The core API returns errors directly, while most of the remainder signal errors using longjmp(). The macro pair json_enter()/json_leave() are analogous to try/finally. However, thrown errors need not be caught; aren't thrown unless an exception context is provided; consistency is maintained if errors are ignored; and a sane and safe value always returned when reading a value. json.c error codes are negative numbers in the range JSON_EBASE to JSON_ELAST, and communicated along with system error codes through a single int value. POSIX guarantees system codes to be positive.

A small regression utility can be built from the source. Defining JSON_MAIN will expose the main() definition, and until documentation can be written usage can be gleaned from the implementation of the utility commands. The utility requires libffi in order to dynamically construct calls with interpolating path expressions, useful for exercising path evaluation. However, the include path for the libffi header is hit-and-miss. And a bug report has been filed with Apple because clang chokes on their broken ffi.h header.

===================================
Jansson
Last Update：2013-09-23
Description：
Jansson is a C library for encoding, decoding and manipulating JSON data. It features:
Jansson 以 C 库的形式提供了针对 JSON 数据编码、解码和操纵的能力。
• Simple and intuitive API and data model 提供简单直观的 API 以及数据模型
• Comprehensive documentation 全面的文档
• No dependencies on other libraries 无第三方库依赖
• Full Unicode support (UTF-8) 对 Unicode 的完全支持（UTF-8 等）
• Extensive test suite 完整的测试集

===================================
vincenthz/libjson

Last Update：2013-09-23（上一个 stable 版本为 v0.8，发布于 2010-09-04）
Description：
libjson is a small C library and small codebase that packs an efficient parser and a configurable printer. libjson is covered by the LGPLv2 license, or at your option the LGPLv3 license.

libjson is a simple library without any dependancies to parse and pretty print the json format (RFC4627).

Here's the feature of libjson:
• Interruptible parser: get the JSON data to the parser any way you want; by appending char by char, or string chunks, the input reading is completely left to the caller.
• No object model integrated: easy integration with any model by the means of a simple callback.
• Small codebase: handcoded parser and efficient factorisation make the code smalls.
• Fast: use efficient code, and small parsing tables to not do any extra work and remains as fast and efficient as possible.
• Full JSON support: tested through a small and precise testsuite.
• No native conversion: callback only string of data and leave the actual representation of data to the caller
• Supports putting limits on nesting level. security against DoS over very deep data.
• Supports putting limits on data (string/int/float) size. security against DoS over very large data object.
• Supports projects-specific allocation functions to integrate completely with projects
• jsonlint utility provided with the library to verify, or reformat json stream. also useful as example on how to use the library.
libjson parser is an interruptible handcoded state parse. the parser takes character or string as input. Since it's interruptible, it's up to the user to feed the stream to the parser, which permits complete flexibility as to whether the data is coming from a pipe, a network socket, a file on disk, a serial line, or crafted by the user.

The parser doesn't create an object tree for you, but each time it comes up with an element in this data, it just callback to the user with the type found and for some type, the data associated with it. It can be compared to the SAX way of XML, hence it's called SAJ (Simple API for JSon).

The parser doesn't convert number to any native C format, but instead callback with a string that is a valid JSon number. JSon number can be of any size, so that's up to user to decide whetever or not, the number can map to native C type int32_t, int64_t, or a complex integer type. As well the user has a choice to refuse the integer at the callback stage if the length is not appropriate.

The parser optionally allows YAML and/or C comments to be ignored if the config structure is set accordingly, otherwise a JSON_ERROR_COMMENT_NOT_ALLOWED is returned.

===================================

Last Update: 2012-12-20 -> 2013-09-23
Description：

jsoncpp is an implementation of a JSON (http://json.org) reader and writer in C++. JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

Posted by OpenID User — 2012-03-14 It's really good apart from the lack of UNICODE support, I'd have to change everything to TCHAR and std::wstring :(
Posted by Sergey Kolomenkin — 2011-02-09 It corrupts heap memory! Developers don't correct even critical bugs for a months (see bug list).
Posted by hypernewbie — 2010-06-16 absolutely horrendous. making a Json::Value global would result in a pure virtual function call crash upon exit. If you try asInt() when the value is a string, you'd get a huge assertion fail. Random access violations everywhere.

1.《json笔记-jsoncpp一个全局对象的bug》，指出由于全局对象构造和析构时可能引发崩溃的问题。2.《C++ Json》，文档整理的比较干净，对 Value 值类型详细进行了代码举例。
3.《JsonCpp使用优化》，从 编译、使用方式、代码，以及编译成哪种库几方面说明优化问题。
4.《JsonCpp简介》，可以看下工程组织方式，和测试例子。

1.解压后的包内容如下：

2.查看 README 文件，并按其中的要求下载并安装配置 scons-local 和 python 。其中 scons-local 解压后，令 scons.py 与 README 位于同级目录。如下图：

3.执行工程配置和编译命令：

 1 python scons.py platform=PLTFRM [TARGET]

 1 where PLTFRM may be one of:
 2     suncc Sun C++ (Solaris)
 3     vacpp Visual Age C++ (AIX)
 4     mingw
 5     msvc6 Microsoft Visual Studio 6 service pack 5-6
 6     msvc70 Microsoft Visual Studio 2002
 7     msvc71 Microsoft Visual Studio 2003
 8     msvc80 Microsoft Visual Studio 2005
 9     linux-gcc Gnu C++ (linux, also reported to work for Mac OS X)
 1 and TARGET may be:
 2     check: build library and run unit tests.

4.执行命令后的结果，如下图：

==================================

Last Update: 2012-12-09 -> 2013-10-09

Very low footprint JSON parser written in portable ANSI C. BSD licensed with no dependencies (i.e. just drop the C file into your project) Never recurses or allocates more memory than it needs Very simple API with operator sugar for C++

1.目录结构

2.提供的 API

json_parse 封装了对 json_parse_ex 的调用

 1 json_value * json_parse(const json_char * json);

json_parse_ex 封装了对 new_value 和 json_value_free 的调用

 1 json_value * json_parse_ex(json_settings * settings, 
 2                            const json_char * json, char * error);
new_value 封装了对 json_alloc 的调用
 1 static int new_value(json_state * state, json_value ** top, 
 2                      json_value ** root, json_value ** alloc, json_type type);

 1 void json_value_free(json_value *);

 1 static void * json_alloc(json_state * state, unsigned long size, int zero);

==================================

Last Update: 2012-11-16 -> 无更新
Description

Rapidjson is an attempt to create the fastest JSON parser and generator.
1. Small but complete. Supports both SAX and DOM style API. SAX parser only a few hundred lines of code.
2. Fast. In the order of magnitude of strlen(). Optionally supports SSE2/SSE4.2 for acceleration.
3. Self-contained. Minimal dependency on standard libraries. No BOOST, not even STL.
4. Compact. Each JSON value is 16 or 20 bytes for 32 or 64-bit machines respectively (excluding text string storage). With the custom memory allocator, parser allocates memory compactly during parsing.
5. Full  RFC4627 compliance. Supports UTF-8, UTF-16 and UTF-32.
6. Support both in-situ parsing (directly decode strings into the source JSON text) and non-destructive parsing (decode strings into new buffers).
7. Parse number to int/unsigned/int64_t/uint64_t/double depending on input
8. Support custom memory allocation. Also, the default memory pool allocator can also be supplied with a user buffer (such as a buffer allocated on user's heap or programme stack) to minimize allocation.

• 依赖库很少；
• 轻量级；
• 对于 Dom 模型层级关系表述的很清楚。

• 只支持标准的 json 格式，一些非标准的 json 格式不支持；
• 缺少一些比较通用的接口，再解析的时候需要自己再封装一层，否则代码量将会很大。

rapidjson is a header-only library. That means, the only thing to be done is to copy rapidjson/include/rapidjson and its sub-directories to your project or other include paths.

==================================

【 json-c-0.10.tar.gz 】

Last Update: 2012-05-30 -> 2013-09-11

Overview

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.

==================================

Last Update: 2011-10-10 -> 2013-08-19
Description

An ultra-lightweight, portable, single-file, simple-as-can-be ANSI-C compliant JSON parser, under MIT license.

Posted by zhou meng — 2010-04-13 Lightweight, easy to use and well documented. Good work! Only not support wide byte like japanese,chinese
Posted by Otto Linnemann — 2010-01-24 Lightweight, easy to use and well documented. Good work! Only memory management should be improved!

==================================

Last Update: 2012-06-25 -> 没有更新
Description

A JSON reader and writer which is super-effiecient and usually runs circles around other JSON libraries. It's highly customizable to optimize for your particular project, and very lightweight. For Windows, OSX, or Linux. Works in any language.

Features

• Lazy or aggressive JSON Parsing
• 100% JSON compliant
• Language independent C interface
• C++ interface
• Test Suite and Example Projects
• C and Bash style comment support
• Automated install via make
• cplusplus.com - style documentation
• Streaming ability
• Security to prevent various forms of Denial of Service

Posted by hu junjie — 2011-07-14
many bugs..
1：
case JSON_TEXT('\v'): //vertical tab res += JSON_TEXT("\\v"); break; case JSON_TEXT('\''): //apostrophe res += JSON_TEXT("\\\'"); break; in rfc4627, '\v', '\'' NOT NEED escape, if do this, other jsonlib will crash, ex: jsoncpp..
2：
json SHOULD transfer in utf8, if define UNICODE, will transfer unicode, if not define UNICODE, libjson can not parse string contant \uxxyy when xx not equ 0
3：
in code JSONWork.cpp *runner++ = (*++p == JSON_TEXT('\"')) ? JSON_TEXT('\1') : *p; //an escaped quote will reak havoc will all of my searching functions, so change it into an illegal character in JSON for convertion later on but iif the node no fetch yet, will not convertion later on, for example: const char *str = "{ \"mt\":\"\\\"str\\\"\" }" // str={"mt":"\"str\""} JSONNode obj = libjson::parse(str); json_string objstr = obj.write(); printf("%s\n", objstr.c_str()); WILL OUTPUT {"mt","\1str\1"}

=============================================

另外，有网友专门对 C 代码的 JSON 解析库进行了比较，参考文章：《四种json c parser的兼容性比较》。

1. 从各个通过的文件数量看， json-c 兼容性是最好的；
2. mjson 和 json-parser 只有一两个文件，适合放到单个模块里用；
3. json-c 采用 autoconf ， 适合库形式；
4. yajl 采用 cmake ， 测试做的比较好；
5. mjson 和 yajl 都支持 sax 事件解析方法。

#### 【STM32】使用keil提供的JSON库——Jansson

2016-09-30 17:24:38

#### janssonAPI翻译

2013年06月29日 336KB 下载

#### 值得推荐的C/C++框架和库 (真的很强大)

2015-01-09 00:52:14

#### 使用keil提供的JSON库——Jansson

2017-12-21 13:38:41

#### linux 下jansson安装和使用

2015-05-27 10:10:16

#### 【STM32】使用keil提供的JSON库——Jansson

2018-02-03 15:21:42

#### 【C】cJSON使用以及在stm32中的应用

2017-06-03 12:11:25

#### 常用的C/C++开源库整理

2016-12-10 16:26:33

#### 常用的C++库总结

2015-06-02 14:44:27

#### cJSON库(构建json与解析json字符串)-c语言

2014-02-25 19:10:54