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
3
votes
1 answer

Convert a MemberIterator to Value

In C++ you can easily get the underlying value from the iterator. ie: std::vector numbers = { 1, 2, 3, 4, 5 }; for (std::vector::iterator it = numbers.begin(); it != numbers.end(); ++it) { int i = *it; std::cout << "i = " << i <<…
graham.reeds
  • 16,230
  • 17
  • 74
  • 137
3
votes
0 answers

rapidjson's assert IsObject() fails randomly while it shouldn't

we are facing an issue where the RAPIDJSON_ASSERT(IsObject()) called by MemberEnd() which is called by HasMember() fails. However, that rapidjson::Value is guaranteed to be an object by other logic. Here is the code snippet: const std::string str =…
LazarusX
  • 2,735
  • 2
  • 22
  • 30
3
votes
1 answer

Parse an array of objects in C++ using rapidjson

I'm trying to parse the following JSON file in c++. I would like to iterate over the 'attributes' array and obtain the value of the string:'value' for a specific value of a string:'name' of that attribute object. For ex: I would like to parse this…
srikarad
  • 65
  • 1
  • 2
  • 6
3
votes
1 answer

Convert from Rapidjson Value to Rapidjson Document

As per the tutorial: Each JSON value is stored in a type called Value. A Document, representing the DOM, contains the root Value of the DOM tree. If so, it should be possible to make a sub-document from a document. If my JSON is: { "mydict":…
dWitty
  • 494
  • 9
  • 22
3
votes
2 answers

c++ - protobuf vs rapidjson data format

using rapidJSON I am able to store data of any type (supported by rapidJSON) as value against a key. Can I do that in protobuf? If so, how? The reason I opted for protobuf over rapidJSON is because of its speed (and key comparison in rapidJSON is…
helix
  • 1,017
  • 3
  • 12
  • 30
3
votes
2 answers

How to merge two json file using rapidjson

I am trying to build a Document by loading two json files. The file loaded last takes the highest priority. In the example below item1.value1 from file B overwrites the value from file A. item1.value2 item2 does not exist in file A so the final…
Frank Liu
  • 1,466
  • 3
  • 23
  • 36
3
votes
2 answers

RapidJson kArrayType with String

I have following code but its cannot compiled. I cannot think about a reason, please hlep. rapidjson::Document jsonDoc; jsonDoc.SetObject(); rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator(); rapidjson::Value…
nilan
  • 61
  • 1
  • 6
3
votes
1 answer

Reading Nested Json using rapidjson

This is my Json array. { "colorsArray":[{ "colorName":"red", "hexValue":"#f00" }, { "colorName":"green", "hexValue":"#0f0" }, { "colorName":"blue", …
Smith Dwayne
  • 2,675
  • 8
  • 46
  • 75
3
votes
1 answer

How to get a wstring in Chinese from rapidjson::Document?

I'm a student, and developing a PC-Client with cpp. I do not know how to deal with which rapidjson with encoding Unicode. I always get a messy code. I am a jackeroo about cpp, how can i get the correct result? I will appreciate it much! Just show a…
毕晓峰
  • 131
  • 1
  • 8
3
votes
1 answer

c++ rapidjson return value

I'm using rapidjson in my project. I have a method which parses a json and returns part of it. static rapidjson::Document getStructureInfo(std::string structureType) { rapidjson::Document d = getStructuresInfo(); rapidjson::Document out; …
Hamed Afshar
  • 173
  • 2
  • 14
3
votes
2 answers

How to look through an array that is inside a .json using rapidjson? (cocos2d-x)

well I think the question is specific, I want to traverse an array that is in a .json that is of the form: { "N" : 5, "Rotacion" : 42, "Igual" : 20, "Inverso" : 0, "RotacionE" : 47, "Espejo" : 22, "Puntuacion" : 0, "_id" : …
D4IVT3
  • 101
  • 1
  • 17
3
votes
1 answer

How to isolate a fault on arm device?

I am using rapidjson on an Arm device and get strange behaviour, when running this code. #include using namespace std; int main() { const char json []="[{\"Type\":\"float\",\"val_param\" : 12.025 }]"; …
john s.
  • 476
  • 9
  • 21
3
votes
1 answer

Create a rapidjson::Value from a JSON string

I want to create a rapidjson::Value from a JSON string, e.g., [1,2,3]. Note: this is not a complete JSON object, it's just a JSON array. In Java I can use objectMapper.readTree("[1,2,3]")to create a JsonNode from a String. My complete C++ code is…
soulmachine
  • 3,917
  • 4
  • 46
  • 56
3
votes
1 answer

rapidjson c++ deallocate Array within Object

I'm using the rapidjson C++ library, with this library you can create a JSON object. Currently I'm having some memory issues. The situation: In my current setup I’ve created a new object, and added value members and an array member to it. The object…
Cédric Verstraeten
  • 574
  • 1
  • 4
  • 15
3
votes
1 answer

rapidjson object as function argument cause compiler error

I try to pass rapidjson::Document object as function argument: std::string json_to_string(rapidjson::Document jmsg) { // Convert JSON document to string rapidjson::StringBuffer buffer; rapidjson::Writer< rapidjson::StringBuffer >…
Max Li
  • 551
  • 2
  • 14