| 1 |
# Features |
| 2 |
|
| 3 |
## General |
| 4 |
|
| 5 |
* Cross-platform |
| 6 |
* Compilers: Visual Studio, gcc, clang, etc. |
| 7 |
* Architectures: x86, x64, ARM, etc. |
| 8 |
* Operating systems: Windows, Mac OS X, Linux, iOS, Android, etc. |
| 9 |
* Easy installation |
| 10 |
* Header files only library. Just copy the headers to your project. |
| 11 |
* Self-contained, minimal dependences |
| 12 |
* No STL, BOOST, etc. |
| 13 |
* Only included `<cstdio>`, `<cstdlib>`, `<cstring>`, `<inttypes.h>`, `<new>`, `<stdint.h>`. |
| 14 |
* Without C++ exception, RTTI |
| 15 |
* High performance |
| 16 |
* Use template and inline functions to reduce function call overheads. |
| 17 |
* Internal optimized Grisu2 and floating point parsing implementations. |
| 18 |
* Optional SSE2/SSE4.2 support. |
| 19 |
|
| 20 |
## Standard compliance |
| 21 |
|
| 22 |
* RapidJSON should be fully RFC4627/ECMA-404 compliance. |
| 23 |
* Support JSON Pointer (RFC6901). |
| 24 |
* Support JSON Schema Draft v4. |
| 25 |
* Support Swagger v2 schema. |
| 26 |
* Support OpenAPI v3.0.x schema. |
| 27 |
* Support Unicode surrogate. |
| 28 |
* Support null character (`"\u0000"`) |
| 29 |
* For example, `["Hello\u0000World"]` can be parsed and handled gracefully. There is API for getting/setting lengths of string. |
| 30 |
* Support optional relaxed syntax. |
| 31 |
* Single line (`// ...`) and multiple line (`/* ... */`) comments (`kParseCommentsFlag`). |
| 32 |
* Trailing commas at the end of objects and arrays (`kParseTrailingCommasFlag`). |
| 33 |
* `NaN`, `Inf`, `Infinity`, `-Inf` and `-Infinity` as `double` values (`kParseNanAndInfFlag`) |
| 34 |
* [NPM compliant](http://github.com/Tencent/rapidjson/blob/master/doc/npm.md). |
| 35 |
|
| 36 |
## Unicode |
| 37 |
|
| 38 |
* Support UTF-8, UTF-16, UTF-32 encodings, including little endian and big endian. |
| 39 |
* These encodings are used in input/output streams and in-memory representation. |
| 40 |
* Support automatic detection of encodings in input stream. |
| 41 |
* Support transcoding between encodings internally. |
| 42 |
* For example, you can read a UTF-8 file and let RapidJSON transcode the JSON strings into UTF-16 in the DOM. |
| 43 |
* Support encoding validation internally. |
| 44 |
* For example, you can read a UTF-8 file, and let RapidJSON check whether all JSON strings are valid UTF-8 byte sequence. |
| 45 |
* Support custom character types. |
| 46 |
* By default the character types are `char` for UTF8, `wchar_t` for UTF16, `uint32_t` for UTF32. |
| 47 |
* Support custom encodings. |
| 48 |
|
| 49 |
## API styles |
| 50 |
|
| 51 |
* SAX (Simple API for XML) style API |
| 52 |
* Similar to [SAX](http://en.wikipedia.org/wiki/Simple_API_for_XML), RapidJSON provides a event sequential access parser API (`rapidjson::GenericReader`). It also provides a generator API (`rapidjson::Writer`) which consumes the same set of events. |
| 53 |
* DOM (Document Object Model) style API |
| 54 |
* Similar to [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) for HTML/XML, RapidJSON can parse JSON into a DOM representation (`rapidjson::GenericDocument`), for easy manipulation, and finally stringify back to JSON if needed. |
| 55 |
* The DOM style API (`rapidjson::GenericDocument`) is actually implemented with SAX style API (`rapidjson::GenericReader`). SAX is faster but sometimes DOM is easier. Users can pick their choices according to scenarios. |
| 56 |
|
| 57 |
## Parsing |
| 58 |
|
| 59 |
* Recursive (default) and iterative parser |
| 60 |
* Recursive parser is faster but prone to stack overflow in extreme cases. |
| 61 |
* Iterative parser use custom stack to keep parsing state. |
| 62 |
* Support *in situ* parsing. |
| 63 |
* Parse JSON string values in-place at the source JSON, and then the DOM points to addresses of those strings. |
| 64 |
* Faster than convention parsing: no allocation for strings, no copy (if string does not contain escapes), cache-friendly. |
| 65 |
* Support 32-bit/64-bit signed/unsigned integer and `double` for JSON number type. |
| 66 |
* Support parsing multiple JSONs in input stream (`kParseStopWhenDoneFlag`). |
| 67 |
* Error Handling |
| 68 |
* Support comprehensive error code if parsing failed. |
| 69 |
* Support error message localization. |
| 70 |
|
| 71 |
## DOM (Document) |
| 72 |
|
| 73 |
* RapidJSON checks range of numerical values for conversions. |
| 74 |
* Optimization for string literal |
| 75 |
* Only store pointer instead of copying |
| 76 |
* Optimization for "short" strings |
| 77 |
* Store short string in `Value` internally without additional allocation. |
| 78 |
* For UTF-8 string: maximum 11 characters in 32-bit, 21 characters in 64-bit (13 characters in x86-64). |
| 79 |
* Optionally support `std::string` (define `RAPIDJSON_HAS_STDSTRING=1`) |
| 80 |
|
| 81 |
## Generation |
| 82 |
|
| 83 |
* Support `rapidjson::PrettyWriter` for adding newlines and indentations. |
| 84 |
|
| 85 |
## Stream |
| 86 |
|
| 87 |
* Support `rapidjson::GenericStringBuffer` for storing the output JSON as string. |
| 88 |
* Support `rapidjson::FileReadStream` and `rapidjson::FileWriteStream` for input/output `FILE` object. |
| 89 |
* Support custom streams. |
| 90 |
|
| 91 |
## Memory |
| 92 |
|
| 93 |
* Minimize memory overheads for DOM. |
| 94 |
* Each JSON value occupies exactly 16/20 bytes for most 32/64-bit machines (excluding text string). |
| 95 |
* Support fast default allocator. |
| 96 |
* A stack-based allocator (allocate sequentially, prohibit to free individual allocations, suitable for parsing). |
| 97 |
* User can provide a pre-allocated buffer. (Possible to parse a number of JSONs without any CRT allocation) |
| 98 |
* Support standard CRT(C-runtime) allocator. |
| 99 |
* Support custom allocators. |
| 100 |
|
| 101 |
## Miscellaneous |
| 102 |
|
| 103 |
* Some C++11 support (optional) |
| 104 |
* Rvalue reference |
| 105 |
* `noexcept` specifier |
| 106 |
* Range-based for loop |