Questions tagged [rapidjson]

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

Rapidjson is an attempt to create the fastest JSON parser and generator.

  • Small but complete. Supports both SAX and DOM style API. SAX parser only a few hundred lines of code.
  • Fast. In the order of magnitude of strlen(). Optionally supports SSE2/SSE4.2 for acceleration.
  • Self-contained. Minimal dependency on standard libraries. No BOOST, not even STL.
  • 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.
  • Full RFC4627 compliance. Supports UTF-8, UTF-16 and UTF-32.
  • Support both in-situ parsing (directly decode strings into the source JSON text) and non-destructive parsing (decode strings into new buffers).
  • Parse number to int/unsigned/int64_t/uint64_t/double depending on input
  • 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.

As the name implies, rapidjson is inspired by rapidxml.

383 questions
4
votes
1 answer

Unable to reorder elements in array - RapidJSON

How to reorder elements in rapidjson array? I have JSON doc that has Test array with three objects as below { "Test":[ { "a":1, "b":"DEMO" }, { "c":2, "d":"DEMO1" }, { "e":5, …
user7588316
  • 77
  • 1
  • 5
4
votes
1 answer

C++ - Passing rapidjson::Document as an argument to a function

I'm passing pointer to rapidjson::Document as an argument. foo(rapidjson::Document* jsonDocument) { std::cout << jsonDocument["name"] << std::endl; } But I cannot do jsonDocument["name"] to access the name attribute. Attempting to not use…
J. Doe
  • 97
  • 2
  • 6
4
votes
4 answers

Can std::string::c_str() be used whenever a string literal is expected?

I would guess that the last two lines in this code should compile. #include "rapidjson/document.h" int main(){ using namespace rapidjson ; using namespace std ; Document doc ; Value obj(kObjectType) ; obj.AddMember("key",…
GetFree
  • 40,278
  • 18
  • 77
  • 104
4
votes
2 answers

conversion from 'size_t' to 'rapidjson::SizeType'

I have this c++ example code: void test() { rapidjson::Document doc; doc.SetObject(); const std::string source = "The quick brown fox jumps over the lazy dog"; rapidjson::Value source_val; source_val.SetString(…
mtb
  • 1,350
  • 16
  • 32
4
votes
1 answer

rapid JSON fails with Assertion `IsObject()' failed

I am trying to parse the data received from a server with RapidJSON . Following is the exact string that is received: [ { "Node": "9478149a08f9", "Address": "172.17.0.2", "ServiceID": "HSS", "ServiceName": "HSS", "ServiceTags":…
Prashant
  • 1,144
  • 8
  • 17
  • 28
4
votes
2 answers

Rounding a double type with RapidJSON

I'm using RapidJSON (https://github.com/miloyip/rapidjson) to create quite big arrays (~ 5 MB) and a lot of the space is waste due to too accurate floating point numbers. E.g. StringBuffer s; Writer
Ollie
  • 127
  • 1
  • 3
  • 8
4
votes
1 answer

Rapidjson: add external sub-document to document

I want to serialize a nested structure to JSON using Rapidjson and I also want to be able to serialize each object separately, so any class that implements ToJson can be serialized to a JSON string. In the following code, the Car has a Wheel member…
Alexandru Irimiea
  • 2,513
  • 4
  • 26
  • 46
4
votes
2 answers

How to get nested JSON Values using Rapidjson in C++

In the below example, how to take the name and balance? { "user": { "Name": "John", "Balance": "2000.53" } }
Karthi
  • 51
  • 1
  • 3
4
votes
2 answers

write temporary variable to Json : I get \u0000

I am facing a strange problem : when i try to add a Json variable inside a for loop, it is not written properly in the output file whereas it works well outside the loop (rapidJson v0.11). Edit : the loop is not the problem but the bug appears even…
Arcyno
  • 4,153
  • 3
  • 34
  • 52
4
votes
3 answers

weird member name string with rapidjson

I have this piece of code which add some members to a Object type Document void test01(rapidjson::Document& doc) { doc.AddMember("test01", 123, doc.GetAllocator()); char name[] = "test02"; doc.AddMember(name, 2, doc.GetAllocator()); …
Ngoc
  • 479
  • 4
  • 12
4
votes
1 answer

Setting a proper size for rapidjson readBuffer

So I've been using rapidjson in a c++ project of mine, and I've figured out how to use it for my project needs. But while cleaning up the my code I saw that I just assigned a random number for my buffer size. char…
user3339357
  • 292
  • 3
  • 16
4
votes
1 answer

Compare rapidjson::Documents

I have two RapidJSON documents. One I created at runtime and other one is read from disk. I want to compare if these two documents are similar or not. What is the best way to compare RapidJSON documents? My JSON looks like this { …
Muhammad Zaighum
  • 560
  • 4
  • 21
4
votes
3 answers

Rapidjson Document

I am trying to create a json document using rapidjson but I don't know how I can replicate part of the following document, in particular the nested object starting with "allocations", for the others elements I do Value…
user1583007
  • 399
  • 1
  • 5
  • 17
4
votes
1 answer

Rapidjson , get a value inside an array of another array

I need to sparse a json of this kind with rapidjson : { "errors":{}, "id":2326625, "source_code":"GOOG", "data": [ …
Malick
  • 6,252
  • 2
  • 46
  • 59
4
votes
4 answers

How to parse with rapidjson from std::string?

How to parse with rapidjson from std::string ? I am trying like (json string is valid, I checked on jsonlint.com) Document document; char * writable = new char[contentString.size() + 1]; std::copy(contentString.begin(), contentString.end(),…
Damir
  • 54,277
  • 94
  • 246
  • 365
1 2
3
25 26