RapidJSON is a JSON parser and generator for C++.

Related tags

rapidjson
Overview

RapidJSON logo

Release version

A fast JSON parser/generator for C++ with both SAX/DOM style API

Tencent is pleased to support the open source community by making RapidJSON available.

Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.

Build status

Linux Windows Coveralls
lin-badge win-badge cov-badge

Introduction

RapidJSON is a JSON parser and generator for C++. It was inspired by RapidXml.

  • RapidJSON is small but complete. It supports both SAX and DOM style API. The SAX parser is only a half thousand lines of code.

  • RapidJSON is fast. Its performance can be comparable to strlen(). It also optionally supports SSE2/SSE4.2 for acceleration.

  • RapidJSON is self-contained and header-only. It does not depend on external libraries such as BOOST. It even does not depend on STL.

  • RapidJSON is memory-friendly. Each JSON value occupies exactly 16 bytes for most 32/64-bit machines (excluding text string). By default it uses a fast memory allocator, and the parser allocates memory compactly during parsing.

  • RapidJSON is Unicode-friendly. It supports UTF-8, UTF-16, UTF-32 (LE & BE), and their detection, validation and transcoding internally. For example, you can read a UTF-8 file and let RapidJSON transcode the JSON strings into UTF-16 in the DOM. It also supports surrogates and "\u0000" (null character).

More features can be read here.

JSON(JavaScript Object Notation) is a light-weight data exchange format. RapidJSON should be in full compliance with RFC7159/ECMA-404, with optional support of relaxed syntax. More information about JSON can be obtained at

Highlights in v1.1 (2016-8-25)

For other changes please refer to change log.

Compatibility

RapidJSON is cross-platform. Some platform/compiler combinations which have been tested are shown as follows.

  • Visual C++ 2008/2010/2013 on Windows (32/64-bit)
  • GNU C++ 3.8.x on Cygwin
  • Clang 3.4 on Mac OS X (32/64-bit) and iOS
  • Clang 3.4 on Android NDK

Users can build and run the unit tests on their platform/compiler.

Installation

RapidJSON is a header-only C++ library. Just copy the include/rapidjson folder to system or project's include path.

Alternatively, if you are using the vcpkg dependency manager you can download and install rapidjson with CMake integration in a single command:

  • vcpkg install rapidjson

RapidJSON uses following software as its dependencies:

  • CMake as a general build tool
  • (optional) Doxygen to build documentation
  • (optional) googletest for unit and performance testing

To generate user documentation and run tests please proceed with the steps below:

  1. Execute git submodule update --init to get the files of thirdparty submodules (google test).
  2. Create directory called build in rapidjson source directory.
  3. Change to build directory and run cmake .. command to configure your build. Windows users can do the same with cmake-gui application.
  4. On Windows, build the solution found in the build directory. On Linux, run make from the build directory.

On successful build you will find compiled test and example binaries in bin directory. The generated documentation will be available in doc/html directory of the build tree. To run tests after finished build please run make test or ctest from your build tree. You can get detailed output using ctest -V command.

It is possible to install library system-wide by running make install command from the build tree with administrative privileges. This will install all files according to system preferences. Once RapidJSON is installed, it is possible to use it from other CMake projects by adding find_package(RapidJSON) line to your CMakeLists.txt.

Usage at a glance

This simple example parses a JSON string into a document (DOM), make a simple modification of the DOM, and finally stringify the DOM to a JSON string.

// rapidjson/example/simpledom/simpledom.cpp`
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>

using namespace rapidjson;

int main() {
    // 1. Parse a JSON string into DOM.
    const char* json = "{\"project\":\"rapidjson\",\"stars\":10}";
    Document d;
    d.Parse(json);

    // 2. Modify it by DOM.
    Value& s = d["stars"];
    s.SetInt(s.GetInt() + 1);

    // 3. Stringify the DOM
    StringBuffer buffer;
    Writer writer(buffer);
    d.Accept(writer);

    // Output {"project":"rapidjson","stars":11}
    std::cout << buffer.GetString() << std::endl;
    return 0;
}

Note that this example did not handle potential errors.

The following diagram shows the process.

simpledom

More examples are available:

  • DOM API

  • SAX API

    • simplereader: Dumps all SAX events while parsing a JSON by Reader.
    • condense: A command line tool to rewrite a JSON, with all whitespaces removed.
    • pretty: A command line tool to rewrite a JSON with indents and newlines by PrettyWriter.
    • capitalize: A command line tool to capitalize strings in JSON.
    • messagereader: Parse a JSON message with SAX API.
    • serialize: Serialize a C++ object into JSON with SAX API.
    • jsonx: Implements a JsonxWriter which stringify SAX events into JSONx (a kind of XML) format. The example is a command line tool which converts input JSON into JSONx format.
  • Schema

    • schemavalidator : A command line tool to validate a JSON with a JSON schema.
  • Advanced

    • prettyauto: A modified version of pretty to automatically handle JSON with any UTF encodings.
    • parsebyparts: Implements an AsyncDocumentParser which can parse JSON in parts, using C++11 thread.
    • filterkey: A command line tool to remove all values with user-specified key.
    • filterkeydom: Same tool as above, but it demonstrates how to use a generator to populate a Document.

Contributing

RapidJSON welcomes contributions. When contributing, please follow the code below.

Issues

Feel free to submit issues and enhancement requests.

Please help us by providing minimal reproducible examples, because source code is easier to let other people understand what happens. For crash problems on certain platforms, please bring stack dump content with the detail of the OS, compiler, etc.

Please try breakpoint debugging first, tell us what you found, see if we can start exploring based on more information been prepared.

Workflow

In general, we follow the "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Checkout a new branch on your fork, start developing on the branch
  4. Test the change before commit, Make sure the changes pass all the tests, including unittest and preftest, please add test case for each new feature or bug-fix if needed.
  5. Commit changes to your own branch
  6. Push your work back up to your fork
  7. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Copyright and Licensing

You can copy and paste the license summary from below.

Tencent is pleased to support the open source community by making RapidJSON available.

Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.

Licensed under the MIT License (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at

http://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed 
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
CONDITIONS OF ANY KIND, either express or implied. See the License for the 
specific language governing permissions and limitations under the License.
Issues
  • Any plans to make new release?

    Any plans to make new release?

    I think that it would be good to flush currently committed changes and make new release :)

    opened by kloczek 1
  • RapidJson issue

    RapidJson issue

    0x00007efe0f73d387 in raise () from /lib64/libc.so.6 #6 0x00007efe0f73ea78 in abort () from /lib64/libc.so.6 #7 0x00007efe0f7361a6 in __assert_fail_base () from /lib64/libc.so.6 #8 0x00007efe0f736252 in __assert_fail () from /lib64/libc.so.6 #9 0x00007efe17226020 in rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8, void>, rapidjson::CrtAllocator>::BeginValue() () from /opt/SMAW/INTP/lib64/libcsb.so #10 0x00007efe1722616d in rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8, void>, rapidjson::CrtAllocator>::StartObject() () from /opt/SMAW/INTP/lib64/libcsb.so #11 0x00007efe17229718 in bool rapidjson::GenericValue<rapidjson::UTF8, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >::Accept<rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8, void>, rapidjson::CrtAllocator> >(rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8, void>, rapidjson::CrtAllocator>&) const () from /opt/SMAW/INTP/lib64/libcsb.so

    getting the above issue, when the josn is given as input, the issue is happening sproadically. Not able to find exact issue. any clue?

    opened by sathyaVanthey 0
  • blackduck complaining about critical security risk

    blackduck complaining about critical security risk

    we are using latest version of rapidjson in our project and running blakduck scan results in showing critical security risk pointing to rapidjson folder but complaining about cereal11 1.3 component which is not used in the project!

    Any idea what should be done about it? is there any version that does not have this issue?

    image

    here is the full description of security risk:

    "An issue was discovered in USC iLab cereal through 1.3.0. It employs caching of std::shared_ptr values, using the raw pointer address as a unique identifier. This becomes problematic if an std::shared_ptr variable goes out of scope and is freed, and a new std::shared_ptr is allocated at the same address. Serialization fidelity thereby becomes dependent upon memory layout. In short, serialized std::shared_ptr variables cannot always be expected to serialize back into their original values. This can have any number of consequences, depending on the context within which this manifests."

    opened by sara66 0
  • SetString构建json时,字符串包含多层转义,AddMember失败, json结果为空

    SetString构建json时,字符串包含多层转义,AddMember失败, json结果为空

    具体string内容 "{"seqid":1618313751765005,"rtc_appid":"appkjeffwr5pzx7","rtc_room_name":"room_name","rtc_room_token":"0048e0b764c7e925af2e614ea3b6eb455e838168f3f161831375805df00471618486558","rtc_room_desc":"room_desc","rtc_room_type":1,"media_type":2,"rtc_userid":5780429,"uk":6563201,"ext":"{\"push_info\":{\"title\":\"123\",\"description\":\"456\",\"schema\":\"baiduboxapp:\\/\\/message\\/openRtcAudioPage?params=%7B%22rtcinfo%22%3A%7B%22inviter_name%22%3A%22%E5%B0%8F%E9%92%89%E9%93%9B%22%2C%22inviter_avatar%22%3A%22https%3A%5C%2F%5C%2Fimg2.baidu.com%5C%2Fit%5C%2Fu%3D3355464299%2C584008140%26fm%3D26%26fmt%3Dauto%26gp%3D0.jpg%22%2C%22media_type%22%3A2%2C%22room_id%22%3A%2223769%22%7D%7D\"},\"inviter_name\":\"小钉铛\",\"inviter_avatar\":\"https:\\/\\/img2.baidu.com\\/it\\/u=3355464299,584008140\u0026fm=26\u0026fmt=auto\u0026gp=0.jpg\"}"}"

    opened by Congyetong 1
  • scan-build static analyzer warning: Dereference of null pointer

    scan-build static analyzer warning: Dereference of null pointer

    I'm seeing issues with scan-build. I run the latest version available on conan, that is from 2020.04.10.

            if (originalPtr == reinterpret_cast<char *>(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) {
                                                                                                             ^
    /home/m/workspace/azure/azure-cloud-adapter-poc2/src/rules.cpp:93:15: note: Calling default constructor for 'GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>'
            rj::Document jsonUpdate;
                         ^~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:2232:14: note: Field 'allocator_' is null
            if (!allocator_)
                 ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:2232:9: note: Taking true branch
            if (!allocator_)
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:2233:56: note: Calling default constructor for 'MemoryPoolAllocator<rapidjson::CrtAllocator>'
                ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
                                             ~~~~~~~~~~~~~~^~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/error/../rapidjson.h:647:37: note: expanded from macro 'RAPIDJSON_NEW'
    #define RAPIDJSON_NEW(TypeName) new TypeName
                                        ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:124:9: note: Null pointer value stored to field 'chunkHead_'
            chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(0), baseAllocator_(baseAllocator), ownBaseAllocator_(0)
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:2233:56: note: Returning from default constructor for 'MemoryPoolAllocator<rapidjson::CrtAllocator>'
                ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
                                             ~~~~~~~~~~~~~~^~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/error/../rapidjson.h:647:37: note: expanded from macro 'RAPIDJSON_NEW'
    #define RAPIDJSON_NEW(TypeName) new TypeName
                                        ^
    /home/m/workspace/azure/azure-cloud-adapter-poc2/src/rules.cpp:93:15: note: Returning from default constructor for 'GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>'
            rj::Document jsonUpdate;
                         ^~~~~~~~~~
    /home/m/workspace/azure/azure-cloud-adapter-poc2/src/rules.cpp:95:2: note: Calling 'SetValueByPointer<rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>, char, 6>'
            rj::SetValueByPointer(jsonUpdate, "/uuid", message.deviceId);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:1363:12: note: Calling 'GenericPointer::Set'
        return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:724:16: note: Calling 'GenericPointer::Create'
            return Create(document) = ValueType(value, document.GetAllocator()).Move();
                   ^~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:518:16: note: Calling 'GenericPointer::Create'
            return Create(document, document.GetAllocator(), alreadyExist);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:462:9: note: '?' condition is true
            RAPIDJSON_ASSERT(IsValid());
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/error/../rapidjson.h:406:29: note: expanded from macro 'RAPIDJSON_ASSERT'
    #define RAPIDJSON_ASSERT(x) assert(x)
                                ^
    /usr/include/assert.h:90:7: note: expanded from macro 'assert'
         (static_cast <bool> (expr)                                         \
          ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:465:9: note: Loop condition is true.  Entering loop body
            for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:466:30: note: Left side of '&&' is false
                if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
                                 ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:472:21: note: Assuming 'kPointerInvalidIndex' is not equal to field 'index'
                    if (t->index == kPointerInvalidIndex) { // must be object name
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:472:17: note: Taking false branch
                    if (t->index == kPointerInvalidIndex) { // must be object name
                    ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:477:25: note: Left side of '&&' is true
                        if (!v->IsArray() && !v->IsObject())
                            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:477:21: note: Taking false branch
                        if (!v->IsArray() && !v->IsObject())
                        ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:481:17: note: Taking false branch
                    if (v->IsArray()) {
                    ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:492:25: note: Assuming the condition is false
                        if (m == v->MemberEnd()) {
                            ^~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:492:21: note: Taking false branch
                        if (m == v->MemberEnd()) {
                        ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:465:40: note: Assuming the condition is true
            for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:465:9: note: Loop condition is true.  Entering loop body
            for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:466:17: note: Left side of '&&' is true
                if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
                    ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:466:33: note: Assuming the condition is true
                if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
                                    ^~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:466:17: note: Left side of '&&' is true
                if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
                    ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:466:54: note: Assuming field 'length' is equal to 1
                if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
                                                         ^~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:466:13: note: Taking true branch
                if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
                ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/pointer.h:467:17: note: Calling 'GenericValue::PushBack'
                    v->PushBack(ValueType().Move(), allocator);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1713:9: note: '?' condition is true
            RAPIDJSON_ASSERT(IsArray());
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/error/../rapidjson.h:406:29: note: expanded from macro 'RAPIDJSON_ASSERT'
    #define RAPIDJSON_ASSERT(x) assert(x)
                                ^
    /usr/include/assert.h:90:7: note: expanded from macro 'assert'
         (static_cast <bool> (expr)                                         \
          ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1714:13: note: Assuming field 'size' is >= field 'capacity'
            if (data_.a.size >= data_.a.capacity)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1714:9: note: Taking true branch
            if (data_.a.size >= data_.a.capacity)
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1715:21: note: Assuming field 'capacity' is equal to 0
                Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
                        ^~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1715:21: note: '?' condition is true
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1715:13: note: Calling 'GenericValue::Reserve'
                Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1694:9: note: '?' condition is true
            RAPIDJSON_ASSERT(IsArray());
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/error/../rapidjson.h:406:29: note: expanded from macro 'RAPIDJSON_ASSERT'
    #define RAPIDJSON_ASSERT(x) assert(x)
                                ^
    /usr/include/assert.h:90:7: note: expanded from macro 'assert'
         (static_cast <bool> (expr)                                         \
          ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1695:13: note: 'newCapacity' is > field 'capacity'
            if (newCapacity > data_.a.capacity) {
                ^~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1695:9: note: Taking true branch
            if (newCapacity > data_.a.capacity) {
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/document.h:1696:64: note: Calling 'MemoryPoolAllocator::Realloc'
                SetElementsPointer(reinterpret_cast<GenericValue*>(allocator.Realloc(GetElementsPointer(), data_.a.capacity * sizeof(GenericValue), newCapacity * sizeof(GenericValue))));
                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:205:13: note: Assuming 'originalPtr' is not equal to null
            if (originalPtr == 0)
                ^~~~~~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:205:9: note: Taking false branch
            if (originalPtr == 0)
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:208:13: note: 'newSize' is not equal to 0
            if (newSize == 0)
                ^~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:208:9: note: Taking false branch
            if (newSize == 0)
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:215:13: note: 'originalSize' is < 'newSize'
            if (originalSize >= newSize)
                ^~~~~~~~~~~~
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:215:9: note: Taking false branch
            if (originalSize >= newSize)
            ^
    /home/m/.conan/data/rapidjson/cci.20200410/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/rapidjson/internal/../allocators.h:219:106: note: Access to field 'size' results in a dereference of a null pointer (loaded from field 'chunkHead_')
            if (originalPtr == reinterpret_cast<char *>(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) {
    
    opened by RelayrMA 0
  • Neat json builder based on initializer_list?

    Neat json builder based on initializer_list?

    I have done some code that builds json/value/document from the initializer list with neat syntax (as some other json libraries). Do you need it? I can easily submit it to repo as addition (maybe as rapidjson utils or something like that). Not for core of course, because there is a thin transition layer.

    Currenlty working syntax:

     const auto sample = BuildJson(
          {{"username", "my_username"},
           {"password", "my_password"},
           {"validation-factors",
            {{"validationFactors",
              Array({
                     {{"name", "remote_address"},
                      {"value", "127.0.0.1"}}
                   })
              }}
          }});
    

    Json builder uses writer API from rapidjson, value/document builder uses regular AddMember/PushBack's.

    opened by crea7or 2
  • get member values

    get member values

    Hey i have a small question,

    Is there an easy way to get data from a second layer of a json?

    { "ID": 1, "Location": { "Lat": 123, "Long": 321 } }

    my code that works is document["ID"].GetInt()

    Is there a way to do this also for the location items?

    i know that document["Location"].HasMember("Long"); works. but is there a way to do it like this?

    Document x = document["Location"].GetMember("Long").GetInt()

    question 
    opened by Rikkamerbeek 1
  • How about bump a new version

    How about bump a new version

    As mentioned above, the latest version is v1.1.0, which was released in 2016. How about bump a new version? So that the vcpkg or conda can use the newer version code.

    opened by inengch 1
  • Build fails on OS X 10.13: zero as null pointer constant  is c++11 warning

    Build fails on OS X 10.13: zero as null pointer constant is c++11 warning

    Building rapidjson-1.1.0 on OS 10.13 with xcode-10.1 (Apple LLVM version 10.0.0 clang-1000.11.45.5) fails:

    [  6%] Building CXX object example/CMakeFiles/tutorial.dir/tutorial/tutorial.cpp.o
    cd /tmp/rapidjson-1.1.0/build/example && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -D__STDC_FORMAT_MACROS -I/tmp/rapidjson-1.1.0/include -I/tmp/rapidjson-1.1.0/example/../include -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers -std=c++11 -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough -Weverything -O2 -g -DNDEBUG -o CMakeFiles/tutorial.dir/tutorial/tutorial.cpp.o -c /tmp/rapidjson-1.1.0/example/tutorial/tutorial.cpp
    In file included from /tmp/rapidjson-1.1.0/example/tutorial/tutorial.cpp:4:
    In file included from /tmp/rapidjson-1.1.0/include/rapidjson/document.h:20:
    In file included from /tmp/rapidjson-1.1.0/include/rapidjson/reader.h:20:
    /tmp/rapidjson-1.1.0/include/rapidjson/allocators.h:69:20: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
                return NULL; // standardize to returning NULL.
                       ^~~~
                       nullptr
    /usr/include/sys/_types/_null.h:30:15: note: expanded from macro 'NULL'
    #define NULL  __DARWIN_NULL
                  ^
    /usr/include/sys/_types.h:43:23: note: expanded from macro '__DARWIN_NULL'
    #define __DARWIN_NULL __null
                          ^
    

    followed by a mile of similar such messages in other source locations. Might be a new issue triggered by -std=c++11 ?

    opened by dmacks 2
  • Revert istreamwrapper to 1.0.2

    Revert istreamwrapper to 1.0.2

    Due to buffering a 4-byte (by default) chunk out of a buffered stream, the underlying std::istream is left in a state inconsistent with the istreamwrapper.

    opened by SeanPMiller 6
Releases(v1.1.0)
  • v1.1.0(Aug 25, 2016)

    Highlights

    Added

    • Add GenericDocument ctor overload to specify JSON type (#369)
    • Add FAQ (#372, #373, #374, #376)
    • Add forward declaration header fwd.h
    • Add @PlatformIO Library Registry manifest file (#400)
    • Implement assignment operator for BigInteger (#404)
    • Add comments support (#443)
    • Adding coapp definition (#460)
    • documenttest.cpp: EXPECT_THROW when checking empty allocator (470)
    • GenericDocument: add implicit conversion to ParseResult (#480)
    • Use <wchar.h> with C++ linkage on Windows ARM (#485)
    • Detect little endian for Microsoft ARM targets
    • Check Nan/Inf when writing a double (#510)
    • Add JSON Schema Implementation (#522)
    • Add iostream wrapper (#530)
    • Add Jsonx example for converting JSON into JSONx (a XML format) (#531)
    • Add optional unresolvedTokenIndex parameter to Pointer::Get() (#532)
    • Add encoding validation option for Writer/PrettyWriter (#534)
    • Add Writer::SetMaxDecimalPlaces() (#536)
    • Support {0, } and {0, m} in Regex (#539)
    • Add Value::Get/SetFloat(), Value::IsLossLessFloat/Double() (#540)
    • Add stream position check to reader unit tests (#541)
    • Add Templated accessors and range-based for (#542)
    • Add (Pretty)Writer::RawValue() (#543)
    • Add Document::Parse(std::string), Document::Parse(const char*, size_t length) and related APIs. (#553)
    • Add move constructor for GenericSchemaDocument (#554)
    • Add VS2010 and VS2015 to AppVeyor CI (#555)
    • Add parse-by-parts example (#556, #562)
    • Support parse number as string (#564, #589)
    • Add kFormatSingleLineArray for PrettyWriter (#577)
    • Added optional support for trailing commas (#584)
    • Added filterkey and filterkeydom examples (#615)
    • Added npm docs (#639)
    • Allow options for writing and parsing NaN/Infinity (#641)
    • Add std::string overload to PrettyWriter::Key() when RAPIDJSON_HAS_STDSTRING is defined (#698)

    Fixed

    • Fix gcc/clang/vc warnings (#350, #394, #397, #444, #447, #473, #515, #582, #589, #595, #667)
    • Fix documentation (#482, #511, #550, #557, #614, #635, #660)
    • Fix emscripten alignment issue (#535)
    • Fix missing allocator to uses of AddMember in document (#365)
    • CMake will no longer complain that the minimum CMake version is not specified (#501)
    • Make it usable with old VC8 (VS2005) (#383)
    • Prohibit C++11 move from Document to Value (#391)
    • Try to fix incorrect 64-bit alignment (#419)
    • Check return of fwrite to avoid warn_unused_result build failures (#421)
    • Fix UB in GenericDocument::ParseStream (#426)
    • Keep Document value unchanged on parse error (#439)
    • Add missing return statement (#450)
    • Fix Document::Parse(const Ch*) for transcoding (#478)
    • encodings.h: fix typo in preprocessor condition (#495)
    • Custom Microsoft headers are necessary only for Visual Studio 2012 and lower (#559)
    • Fix memory leak for invalid regex (26e69ffde95ba4773ab06db6457b78f308716f4b)
    • Fix a bug in schema minimum/maximum keywords for 64-bit integer (e7149d665941068ccf8c565e77495521331cf390)
    • Fix a crash bug in regex (#605)
    • Fix schema "required" keyword cannot handle duplicated keys (#609)
    • Fix cmake CMP0054 warning (#612)
    • Added missing include guards in istreamwrapper.h and ostreamwrapper.h (#634)
    • Fix undefined behaviour (#646)
    • Fix buffer overrun using PutN (#673)
    • Fix rapidjson::value::Getstd::string() may returns wrong data (#681)
    • Add Flush() for all value types (#689)
    • Handle malloc() fail in PoolAllocator (#691)
    • Fix builds on x32 platform. #703

    Changed

    • Clarify problematic JSON license (#392)
    • Move Travis to container based infrastructure (#504, #558)
    • Make whitespace array more compact (#513)
    • Optimize Writer::WriteString() with SIMD (#544)
    • x86-64 48-bit pointer optimization for GenericValue (#546)
    • Define RAPIDJSON_HAS_CXX11_RVALUE_REFS directly in clang (#617)
    • Make GenericSchemaDocument constructor explicit (#674)
    • Optimize FindMember when use std::string (#690)
    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(May 14, 2015)

    Added

    • Add Value::XXXMember(...) overloads for std::string (#335)

    Fixed

    • Include rapidjson.h for all internal/error headers.
    • Parsing some numbers incorrectly in full-precision mode (kFullPrecisionParseFlag) (#342)
    • Fix alignment of 64bit platforms (#328)
    • Fix MemoryPoolAllocator::Clear() to clear user-buffer (0691502573f1afd3341073dd24b12c3db20fbde4)

    Changed

    • CMakeLists for include as a thirdparty in projects (#334, #337)
    • Change Document::ParseStream() to use stack allocator for Reader (ffbe38614732af8e0b3abdc8b50071f386a4a685)
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Apr 25, 2015)

  • v1.0.0(Apr 21, 2015)

    This is the final v1.0.0 release of RapidJSON.

    After the v1.0-beta, a lot of efforts have been put to make RapidJSON 100% line-of-code covered by the unit tests.

    Major changes since v1.0-beta

    • Fixed a bug in trimming long number sequence (4824f12efbf01af72b8cb6fc96fae7b097b73015)
    • Fix double quote in unicode escape (#288)
    • Fix negative zero roundtrip (double only) (#289)
    • Remove an invalid Document::ParseInsitu() API (e7f1c6dd08b522cfcf9aed58a333bd9a0c0ccbeb)
    • Remove dead branches and add more unit tests for coverage
    • Standardize behavior of memcpy() and malloc() (0c5c1538dcfc7f160e5a4aa208ddf092c787be5a, #305, 0e8bbe5e3ef375e7f052f556878be0bd79e9062d)
    • Add version macros (#311)
    Source code(tar.gz)
    Source code(zip)
  • v1.0-beta(Apr 8, 2015)

    This is the first pre-release of RapidJSON at GitHub.

    There have been a lot of improvements and bug fixes since v0.11. Some notable ones are listed as follows.

    Features

    • RFC 7159 (#101)
    • Optional Iterative Parser (#76)
    • Deep-copy values (#20)
    • Error code and message (#27)
    • ASCII Encoding (#70)
    • kParseStopWhenDoneFlag (#83)
    • kParseFullPrecisionFlag (881c91d696f06b7f302af6d04ec14dd08db66ceb)
    • Add Key() to handler concept (#134)
    • C++11 compatibility and support (#128)

    Optimizations

    • Optimized number-to-string and vice versa conversions (#137, #80)
    • Short-String Optimization (#131)
    • Local stream optimization by traits (#32)

    Build

    • Migrating from Premake to CMAKE (#192)
    • Remove other JSON libraries for performance comparison (#180)
    • Travis & Appveyor Continuous Integration, with Valgrind verification (#24, #242)
    • Resolve all warning reports

    Documentation

    • Redo all documentation
    • English, Simplified Chinese
    • Doxygen with Markdown
    • Gitbook

    Notes

    Note that the copyright owner is changed but the project is still distributed under MIT license.

    Please help testing this release in your development platform. The API shall not be changed in v1.0. Only bug fixes are permitted.

    It is planned to release the official v1.0 at 15 April 2015.

    Source code(tar.gz)
    Source code(zip)
A fast JSON parser/generator for C++ with both SAX/DOM style API

A fast JSON parser/generator for C++ with both SAX/DOM style API Tencent is pleased to support the open source community by making RapidJSON available

Tencent 10.5k Feb 19, 2021
JSON for Modern C++

Design goals Sponsors Integration CMake Package Managers Pkg-config Examples JSON as first-class data type Serialization / Deserialization STL-like ac

Niels Lohmann 23.2k Feb 19, 2021
Parsing gigabytes of JSON per second

simdjson : Parsing gigabytes of JSON per second JSON is everywhere on the Internet. Servers spend a *lot* of time parsing it. We need a fresh approach

null 12.9k Feb 19, 2021
🔋 In-place lightweight JSON parser

?? JSON parser for C This is very simple and very powerful JSON parser. It creates DOM-like data structure and allows to iterate and process JSON obje

Recep Aslantas 17 Jan 8, 2021
A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON

JSONCONS jsoncons is a C++, header-only library for constructing JSON and JSON-like data formats such as CBOR. For each supported data format, it enab

Daniel Parker 384 Feb 18, 2021
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/

\mainpage json-c Overview and Build Status Building on Unix Prerequisites Build commands CMake options Testing Building with vcpkg Linking to libjson-

json-c 2.1k Feb 19, 2021
A killer modern C++ library for interacting with JSON.

JSON Voorhees Yet another JSON library for C++. This one touts new C++11 features for developer-friendliness, an extremely slow-speed parser and no de

Travis Gockel 120 Nov 23, 2020
C++ header-only JSON library

Welcome to taoJSON taoJSON is a C++ header-only JSON library that provides a generic Value Class, uses Type Traits to interoperate with C++ types, use

The Art of C++ 335 Jan 31, 2021
Universal configuration library parser

LIBUCL Table of Contents generated with DocToc Introduction Basic structure Improvements to the json notation General syntax sugar Automatic arrays cr

Vsevolod Stakhov 1.3k Feb 11, 2021
JSON & BSON parser/writer

jbson is a library for building & iterating BSON data, and JSON documents in C++14. \tableofcontents Features # {#features} Header only. Boost license

Chris Manning 33 Dec 11, 2020
Ultralightweight JSON parser in ANSI C

cJSON Ultralightweight JSON parser in ANSI C. Table of contents License Usage Welcome to cJSON Building Copying the source CMake Makefile Vcpkg Includ

Dave Gamble 5.5k Feb 19, 2021
JSON parser and generator for C/C++ with scanf/printf like interface. Targeting embedded systems.

JSON parser and emitter for C/C++ Features ISO C and ISO C++ compliant portable code Very small footprint No dependencies json_scanf() scans a string

Cesanta Software 514 Feb 12, 2021
a JSON parser and printer library in C. easy to integrate with any model.

libjson - simple and efficient json parser and printer in C Introduction libjson is a simple library without any dependancies to parse and pretty prin

Vincent Hanquez 225 Jan 23, 2021
convert json/xml/bson to c++ struct

xpack 用于在C++结构体和json/xml之间互相转换, bson在xbson中支持。 只需要头文件, 无需编译库文件。 具体可以参考example的例子 基本用法 容器支持 FLAG 别名 位域 继承 枚举 自定义编解码 char数组 第三方类和结构体 格式化缩进 XML数组 Qt支持 重要

null 31 Mar 2, 2021