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
20
votes
4 answers

How to serialize RapidJSON document to a string?

How to serialize RapidJSON document to a string? In all the examples the serializing text is redirected to the standard output through the FileStream, but I need to redirect it to a string variable.
Lochana Thenuwara
  • 415
  • 2
  • 4
  • 12
19
votes
8 answers

Retrieving a nested object inside a JSON string using rapidjson

I need to retrieve a nested object inside a JSON string and I'm trying to do it using rapidjson. All I've found is how to retrieve arrays and basic types, but not sub-objects. I have created the following toy example which gives an…
pparescasellas
  • 620
  • 1
  • 12
  • 23
14
votes
5 answers

iterate and retrieve nested object in JSON using rapidjson

I am parsing a JSON structure which is similar as follows { "item1" : "value1" "item2" : "value2" // ... "itemn" : { "outernestedItem1" : { "innerNestedItem1" : "valuen1" "innerNestedItem2" :…
Ruturaj
  • 630
  • 1
  • 6
  • 20
13
votes
1 answer

rapidjson proper json creation

I'm trying to create a json using rapidjson and I am having some unexpected problems with generating a proper output. I'm creating and populating a document like this: Document d; d.SetObject(); rapidjson::Document::AllocatorType& allocator =…
André Moreira
  • 1,669
  • 4
  • 21
  • 35
12
votes
1 answer

How to read json file using rapidjson and output to std::string?

How can I read a *.json file and put the output on a std::string? I have this sample, but I always get null on std::string. #include #include #include "rapidjson/writer.h" #include…
waas1919
  • 2,365
  • 7
  • 44
  • 76
10
votes
1 answer

Is there way to use rapidjson with std::string efficiently?

I'm trying to work with rapidjson. I want to generate string and add it to some rapidjson::Value which is object. I was using std::string when worked with qjson, but in case of rapidjson it seems inappropriate. I don't want to generate string and…
ckorzhik
  • 758
  • 2
  • 7
  • 21
9
votes
2 answers

get array data from json file using rapidjson

I'm new in rapidjson. I have test.json which contains {"points": [1,2,3,4]} and I use following code to get data of array "points" std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("json/deluxe/treasurebag.json"); …
Nikel Arteta
  • 548
  • 1
  • 6
  • 25
9
votes
3 answers

rapidjson: working code for reading document from file?

I need a working c++ code for reading document from file using rapidjson: https://code.google.com/p/rapidjson/ In the wiki it's yet undocumented, the examples unserialize only from std::string, I haven't a deep knowledge of templates. I serialized…
morde
  • 231
  • 1
  • 3
  • 8
8
votes
2 answers

How can I add string pairs to a document of rapidjson

I want to create a json string using rapidjson. But I got a error: unable to convert std::string to rapidjson::Type. int x = 111; string className = "myclass"; Document doc; auto& allocator = doc.GetAllocator(); doc.AddMember("x",…
Zen
  • 5,065
  • 8
  • 29
  • 49
8
votes
4 answers

How to parse bigdata json file (wikidata) in C++ efficiently?

I have a single json file which is about 36 GB (coming from wikidata) and I want to access it more efficiently. Currently I'm using rapidjsons SAX-style API in C++ - but parsing the whole file takes on my machine about 7415200 ms (=120 minutes). I…
Constantin
  • 8,721
  • 13
  • 75
  • 126
7
votes
1 answer

What's the purpose of this function that does nearly nothing?

I'm currently reading the code of RapidJSON, and I don't understand this bit of code: //! Reserve n characters for writing to a stream. template inline void PutReserve(Stream& stream, size_t count) { (void)stream; …
maidamai
  • 712
  • 9
  • 26
7
votes
1 answer

rapidjson pretty print using JSON string as input to the writer

Following rapidjson documentation I'm able to generate a pretty-printed JSON ouput writting in a key-by-key approach, e.g.: rapidjson::StringBuffer s; rapidjson::PrettyWriter writer(s); …
fgalan
  • 11,732
  • 9
  • 46
  • 89
7
votes
1 answer

is it possible to try catch an assert call in a static library(c++)

Is it possible to try catch an assert call in c++? Im using the library rapidjson(static library) and its annoying because if it fails to find something in a json file it calls assert. When i want to avoid it calling assert and do the error handling…
GameHog
  • 73
  • 1
  • 7
7
votes
2 answers

Looping over an array in RapidJson and getting the object elements

How do I get the value out of a ConstrValueIterator? In this case I know that the elements of the array are dictionaries (aka objects). Code summed up: for (rapidjson::Value::ConstValueIterator itr = rawbuttons.Begin(); itr != rawbuttons.End();…
Jonny
  • 15,955
  • 18
  • 111
  • 232
7
votes
2 answers

rapidjson extract key and value

I'm trying to extract the key and the value of an object in array but don't find the proper getter: for (Value::ConstValueIterator itr = document["params"].Begin(); itr != document["params"].End(); ++itr) { for (Value::MemberIterator m =…
Pooya
  • 992
  • 2
  • 10
  • 31
1
2 3
25 26