2014-07-07 19:15:10 +08:00
# Features
2014-06-29 16:03:33 +08:00
## General
* Cross-platform
2014-06-29 16:25:08 +08:00
* Compilers: Visual Studio, gcc, clang, etc.
* Architectures: x86, x64, ARM, etc.
* Operating systems: Windows, Mac OS X, Linux, iOS, Android, etc.
2014-06-29 16:03:33 +08:00
* Easy installation
* Header files only library. Just copy the headers to your project.
2014-06-29 16:25:08 +08:00
* Self-contained, minimal dependences
2014-06-29 16:03:33 +08:00
* No STL, BOOST, etc.
2014-07-01 12:56:40 +08:00
* Only included `<cstdio>` , `<cstdlib>` , `<cstring>` , `<inttypes.h>` , `<new>` , `<stdint.h>` .
2014-06-29 16:25:08 +08:00
* Without C++ exception, RTTI
2014-06-29 16:03:33 +08:00
* High performance
* Use template and inline functions to reduce function call overheads.
2015-02-08 19:08:26 +08:00
* Internal optimized Grisu2 and floating point parsing implementations.
2015-04-15 14:57:20 +08:00
* Optional SSE2/SSE4.2 support.
2014-06-29 16:03:33 +08:00
## Standard compliance
* RapidJSON should be fully RFC4627/ECMA-404 compliance.
2016-08-25 14:35:17 +08:00
* Support JSON Pointer (RFC6901).
* Support JSON Schema Draft v4.
2014-07-04 10:35:29 +08:00
* Support Unicode surrogate.
2014-06-29 16:03:33 +08:00
* Support null character (`"\u0000"` )
2014-06-29 16:25:08 +08:00
* For example, `["Hello\u0000World"]` can be parsed and handled gracefully. There is API for getting/setting lengths of string.
2015-10-22 10:58:58 +08:00
* Support optional relaxed syntax.
2016-04-15 10:18:16 +08:00
* Single line (`// ...` ) and multiple line (`/* ... */` ) comments (`kParseCommentsFlag` ).
* Trailing commas at the end of objects and arrays (`kParseTrailingCommasFlag` ).
2016-08-25 14:35:17 +08:00
* `NaN` , `Inf` , `Infinity` , `-Inf` and `-Infinity` as `double` values (`kParseNanAndInfFlag` )
* [NPM compliant ](http://github.com/miloyip/rapidjson/blob/master/doc/npm.md ).
2014-06-29 16:03:33 +08:00
## Unicode
* Support UTF-8, UTF-16, UTF-32 encodings, including little endian and big endian.
* These encodings are used in input/output streams and in-memory representation.
2014-06-29 16:35:16 +08:00
* Support automatic detection of encodings in input stream.
2014-06-29 16:03:33 +08:00
* Support transcoding between encodings internally.
* For example, you can read a UTF-8 file and let RapidJSON transcode the JSON strings into UTF-16 in the DOM.
* Support encoding validation internally.
* For example, you can read a UTF-8 file, and let RapidJSON check whether all JSON strings are valid UTF-8 byte sequence.
2014-06-29 16:25:08 +08:00
* Support custom character types.
* By default the character types are `char` for UTF8, `wchar_t` for UTF16, `uint32_t` for UTF32.
2014-06-29 16:03:33 +08:00
* Support custom encodings.
2014-06-29 16:25:08 +08:00
## API styles
* SAX (Simple API for XML) style API
2014-07-05 17:11:15 +02:00
* 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.
2014-06-29 16:25:08 +08:00
* DOM (Document Object Model) style API
2014-07-05 17:11:15 +02:00
* 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.
* 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.
2014-06-29 16:25:08 +08:00
2015-02-08 19:08:26 +08:00
## Parsing
2014-06-29 16:25:08 +08:00
2015-02-08 19:08:26 +08:00
* Recursive (default) and iterative parser
* Recursive parser is faster but prone to stack overflow in extreme cases.
* Iterative parser use custom stack to keep parsing state.
2014-07-04 10:35:29 +08:00
* Support *in situ* parsing.
2014-06-29 16:25:08 +08:00
* Parse JSON string values in-place at the source JSON, and then the DOM points to addresses of those strings.
* Faster than convention parsing: no allocation for strings, no copy (if string does not contain escapes), cache-friendly.
* Support 32-bit/64-bit signed/unsigned integer and `double` for JSON number type.
2015-02-08 19:08:26 +08:00
* Support parsing multiple JSONs in input stream (`kParseStopWhenDoneFlag` ).
* Error Handling
* Support comprehensive error code if parsing failed.
* Support error message localization.
2014-06-29 16:25:08 +08:00
2015-02-08 19:08:26 +08:00
## DOM (Document)
2014-06-29 16:25:08 +08:00
2015-02-08 19:08:26 +08:00
* RapidJSON checks range of numerical values for conversions.
* Optimization for string literal
* Only store pointer instead of copying
* Optimization for "short" strings
* Store short string in `Value` internally without additional allocation.
2016-08-25 14:35:17 +08:00
* For UTF-8 string: maximum 11 characters in 32-bit, 21 characters in 64-bit (13 characters in x86-64).
2015-02-08 19:08:26 +08:00
* Optionally support `std::string` (define `RAPIDJSON_HAS_STDSTRING=1` )
2014-06-29 16:25:08 +08:00
2015-02-08 19:08:26 +08:00
## Generation
2014-06-29 16:25:08 +08:00
2014-07-05 17:11:15 +02:00
* Support `rapidjson::PrettyWriter` for adding newlines and indentations.
2014-06-29 16:25:08 +08:00
2014-06-29 16:03:33 +08:00
## Stream
2014-07-05 17:11:15 +02:00
* Support `rapidjson::GenericStringBuffer` for storing the output JSON as string.
2014-07-08 14:11:08 +08:00
* Support `rapidjson::FileReadStream` and `rapidjson::FileWriteStream` for input/output `FILE` object.
2014-06-29 16:03:33 +08:00
* Support custom streams.
## Memory
* Minimize memory overheads for DOM.
* Each JSON value occupies exactly 16/20 bytes for most 32/64-bit machines (excluding text string).
* Support fast default allocator.
* A stack-based allocator (allocate sequentially, prohibit to free individual allocations, suitable for parsing).
* User can provide a pre-allocated buffer. (Possible to parse a number of JSONs without any CRT allocation)
2014-06-29 16:35:16 +08:00
* Support standard CRT(C-runtime) allocator.
2014-06-29 16:03:33 +08:00
* Support custom allocators.
2015-02-08 19:08:26 +08:00
## Miscellaneous
* Some C++11 support (optional)
* Rvalue reference
* `noexcept` specifier
2016-08-25 14:35:17 +08:00
* Range-based for loop