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
2 answers

Set floating point precision using rapidjson

Is there a way to control the output precision in JSON generated using rapidjson? For example: writer.String("length"); writer.Double(1.0 / 3.0); This generates something like: { length: 0.33333333 } I'm sending a lot of values and only need two…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
2
votes
0 answers

Assertion error (!hasRoot_) during rapidjson::writer usage

Advance Thanks for the help. I have a requirement to create array of json records of 10KB each. I am using rapidjson::writer and rapidjson::stringbuffer. I am getting Assertion error (at writer.h #488, !hasRoot_ error) for the below mentioned code…
Hegde
  • 21
  • 2
2
votes
0 answers

RapidJSON and clang-tidy and thread_local

I am working on a C++17-project which I am compiling under Linux with GCC 9. However, I EDIT the project under Windows 11 in QT Creator 10 using clangd/clangTidy(16.0.0). Now, when it comes to code that uses thread_local, I get errors in clang-tidy,…
SoulfreezerXP
  • 459
  • 1
  • 5
  • 19
2
votes
1 answer

When should you use CrtAllocator vs MemoryPoolAllocator in RapidJSON?

I know that the CrtAllocator is the C runtime allocator and uses malloc/realloc/free, and I know that the MemoryPoolAllocator is the default allocator and allocates memory sequentially. I don't understand why the MemoryPoolAllocator is considered…
ajoseps
  • 1,871
  • 1
  • 16
  • 29
2
votes
0 answers

RapidJSON Pointer Set/Create/GetWithDefault causes core dump C++11

I'm running into this error Unhandled Fault: Alignment Exception when utilizing RapidJSON Pointers. I've tried various things with minimal success. rapidjson::Document…
kates
  • 21
  • 2
2
votes
0 answers

How to parse a valid JSON file that has non valid field inside?

I know that this may seem a strange question, but, the input of my algorithm is a stream of JSON strings composed by syntactically correct JSON blocks, at least for all blocks but this. A block in the stream has this structure: { "comment", { …
Carmine
  • 109
  • 2
  • 8
2
votes
2 answers

Cannot use std::string variable in RapidJSON function call

I am all new to C++ and am running into an issue. I am using rapidJSON to create JSON documents. void setKeyValue() { Value obj(kObjectType); Value key("key"); Value val(42);; obj.AddMember(key, val,…
SomeDutchGuy
  • 2,249
  • 4
  • 16
  • 42
2
votes
0 answers

RapidJSON pointer notation for member of object in array of objects

I have a document that has an array of objects. I know how to retrieve the object itself using pointer notation. rapidjson::Value* ptr = GetValueByPointer(document, "/object1/object2/array/0"); I can then access members of that object as…
User51610
  • 453
  • 5
  • 18
2
votes
1 answer

Why is rapidjson giving me problems with std::string?

I am trying to use an std::string with RapidJson using namespace std; using namespace rapidjson; const char* json = "{\n" " \"id\": null\n" " \"code\": null\n" "}"; Document d; string a…
Ivan Solis
  • 23
  • 1
  • 5
2
votes
0 answers

RapidJSON doesn't reuse memory after removing members from a complex document

[This is a followup to a related question here.] My code has a loop like the following: Document d(kObjectType); while (not done() and getNewStuff(d)) { process(d); d.RemoveAllMembers(); } While this code produces the…
webbnh
  • 66
  • 6
2
votes
3 answers

Cpp: JSON parser in Cpp that provide support Serialize/Deserialize feature, converting JSON objects to user-defined classes?

I'm working on native C++ development and looking for JSON parser that can handle complex JSON files and convert into class objects. I've looked at native benchmarks for JSON parsers available in C++ and came to conclusion that RapidJSON is…
akshay dhule
  • 167
  • 3
  • 17
2
votes
3 answers

Rapidjson Iterating over and Getting Values of Complex JSON Object Members

I have the following JSON object { "prog":[ { "iUniqueID":1, "bGroup":1, "inFiles":[ { "sFileType":"Zonal Data 1", "bScenarioSpecific":0, "pos":{ …
Raymond Kalonji
  • 345
  • 3
  • 14
2
votes
1 answer

CMake: How to handle multiple versions of same libraries?

in my project I am using the header only library rapidjson v1.1.0. └── my_project ├── CMakeLists.txt ├── src │ ├── 3rdParty/tiny_dnn (header only) │ ├── CMakeLists.txt │ ├── src │ └── rapidjson_v0.2 │ └──…
2
votes
1 answer

RapidJSON/C++: Better ways to create objects/arrays?

I've just begun using RapidJSON; currently, I've got a STL map of strings; and I want to represent it as JSON. So far, I've done this: using JSONDocument = rapidjson::GenericDocument>; using JSONValue =…
2
votes
3 answers

Access fields of a JSON array using RapidJSON in C++

I am new using the RapidJSON library and I want to know how I can access specific elements within an array in JSON format, this is the JSON: { "products": [ { "id_product": 1, "product_name": "Beer", "product_price": 120.00 …
Noe Cano
  • 495
  • 2
  • 8
  • 22