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
1
vote
0 answers

Get Object from object array based on value of certain key with rapidjson

I have this JSON file I'm making a web request to. It's an array of JSON objects as you can see and I want to get the object that has a matching hash to. What I have my end goal is to get the upVotes and downVotes from stats. Here is an individual…
1
vote
1 answer

How do I pass a rapidjson::Value& to a function?

rapidjson::Document doc; //parse doc const rapidjson::Value& object = doc["Object"]; checkSomething(object); checkSomething(const rapidjson::Value& object) const { //do something with it } I am trying to pass a part of the JSON document to a…
Moosi312
  • 31
  • 1
  • 6
1
vote
0 answers

Limit JSON nesting level at parsing stage in rapidjson

Is there any way to limit the nesting level in the JSON document at the parsing stage in rapidjson (in order to limit the resource consumption, e.g. memory)? For instance set maximum nesting level to 100, so if the document to be parsed overpassed…
fgalan
  • 11,732
  • 9
  • 46
  • 89
1
vote
4 answers

Read nested rapidjson in c++

I tried something like rapidjson::Value& response = Doc[level1][level2][level3]... for (auto m=response.MemberBegin();m!=response.MemberEnd();++m) { } but it doesn't seem to work. Any ideas?
ZhenKai
  • 125
  • 2
  • 9
1
vote
0 answers

okhttp returns null response

```protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); ctx=getApplicationContext(); txtString= (TextView)findViewById(R.id.txtString); httpClient =…
Sara
  • 11
  • 4
1
vote
1 answer

How to print or to_string() a nested JSON with unknown structure using Rapidjson

The Programming Language : C++ Environment : Linux Ubuntu Compiler : gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 I am parsing a nested JSON with unknown structure ( each key can be a json document ) we don't know the key names and values. RapidJson…
Mohsen
  • 59
  • 1
  • 8
1
vote
3 answers

Iterating over a vector containing pointers in c++

I got a function that accepts a pointer to a rapidjson::Value type and stores the item at that location into a rapidjson::Value of type kArrayType. void addBlock(rapidjson::Value* block) { blocksArray.PushBack(*block, allocator); } This…
SomeDutchGuy
  • 2,249
  • 4
  • 16
  • 42
1
vote
1 answer

I'm trying to return a rapidjson::Value from a GMocked class but I can't seem to get it to work

I'm trying to unit test one of my classes, but am struggling to return a rapidjson::Value from my mocked class. I've looked around the internet, and haven't been successful so far. This is my last ditch attempt. The code I'm running is the…
Andy
  • 339
  • 3
  • 17
1
vote
0 answers

RapidJson difference between kTrueType and kFalseType

I am wondering what's the difference between kTrueType and kFalseType in rapidjson. For example: void writeTest(){ rapidjson::Document document; rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); rapidjson::Value…
Rocking chief
  • 1,039
  • 3
  • 17
  • 31
1
vote
0 answers

rapidjson modifying document creating object and removing member causes assert when writing document

I have a bit of code where I parse a json file, edit it, and save it again. The code works fine as long as I don't create an object and then remove a member. Doing those two steps causes an assertion in the object where the member was removed when…
Mikey A. Leonetti
  • 2,834
  • 3
  • 22
  • 36
1
vote
1 answer

Save json with rapidjson directly on file

I'm java programmer and I'm learning C++ for my personal project for a parser bitcoin core, my parser converts the information on file dat bitcoin to the json file. Now my problem is when I create the big json with rapidjson with Writer on…
vincenzopalazzo
  • 1,487
  • 2
  • 7
  • 35
1
vote
2 answers

Can't concatenate input string for retreiving JSON value... but can hardcode it

I'm attempting to loop through a list of objects within a JSON to find the object with a matching KVP (in C++ using RapidJSON). I've managed to retrieve the value using a hardcoded pointer but cannot get the function GetValueByPointer(document,…
Fishish
  • 165
  • 1
  • 10
1
vote
0 answers

Move memory owned by one rapidjson allocator to another one

I have the following code: rapidjson::Document response; // parse some json string into response std::vector elements; elements.reserve(response["array"].Size()); for (auto&& array_element : response["array"].GetArray()) { …
1
vote
0 answers

Can you convert a c++ rapid json object to a Python Json object?

I am building a C++ project that connects to a customer-owned Python codebase and sending a json object to the python code. Because the python codebase is customer-owned, I cannot modify the python codebase to receive a json string. I am using…
1
vote
1 answer

Print JSON with matching key - RapidJSON

I'm trying to print from a JSON only the values that matching some keys: #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" #include using namespace rapidjson; char* kTypeNames[] = {…
DDBE
  • 325
  • 3
  • 13