Questions tagged [rapidjson]

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

rapidjson
Filter by
Sorted by
Tagged with
20 votes
4 answers
55k views

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's user avatar
19 votes
8 answers
40k views

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 ...
pparescasellas's user avatar
14 votes
5 answers
41k views

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" : "...
Ruturaj's user avatar
  • 630
13 votes
1 answer
16k views

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(); ...
André Moreira's user avatar
12 votes
1 answer
19k views

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 <rapidjson/document.h> #include <rapidjson/...
waas1919's user avatar
  • 2,505
10 votes
2 answers
17k views

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 ...
ckorzhik's user avatar
  • 778
9 votes
3 answers
23k views

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 ...
morde's user avatar
  • 231
9 votes
2 answers
27k views

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()->...
Nikel Arteta's user avatar
8 votes
2 answers
19k views

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 = ...
Zen's user avatar
  • 5,273
8 votes
4 answers
2k views

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 ...
Constantin's user avatar
  • 8,799
7 votes
1 answer
12k views

stringify with rapidjson

I'm using socket.io-clientpp, https://github.com/ebshimizu/socket.io-clientpp, which uses rapidjson. When a event is received, my function is called : void data_published(socketio::socketio_events&...
Robert Cervera's user avatar
7 votes
4 answers
19k views

Perform a copy of Document object of rapidjson

I'm making a class and I want to return my class inside a method. My class has a rapidjson::Document object. You can see the previous problems here: LNK2019: "Unresolved external symbol" ...
SysDragon's user avatar
  • 9,830
7 votes
1 answer
15k views

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<rapidjson::...
fgalan's user avatar
  • 12k
7 votes
2 answers
15k views

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(); ...
Pooya's user avatar
  • 1,002
7 votes
2 answers
12k views

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 =...
Jonny's user avatar
  • 16.1k
7 votes
1 answer
265 views

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<typename Stream> inline void PutReserve(Stream&...
maidamai's user avatar
  • 712
7 votes
1 answer
3k views

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 ...
GameHog's user avatar
  • 73
6 votes
1 answer
4k views

What is the difference between Document and Value in rapidjson?

Seems Document can also be used as parameter in void test(Value value); and both Document and Value can have child value, what is the difference between them?
ggrr's user avatar
  • 7,787
6 votes
5 answers
3k views

How to prevent JSON parser crashing when there are illigal characters in JSON?

Due to some communication errors, I am sometimes receiving JSON strings with some illegal characters: "{messageType\" : \"Test1\", \"from\" : \"F2D0B5C6-9875-46B5-8D4F\"}����1" These illegal ...
Deekshith's user avatar
  • 1,564
6 votes
2 answers
1k views

How to reuse Stack Allocator in RapidJSON without reallocating memory

I'm running a single-threaded system in FreeRTOS with limited resources. I already preallocate buffers for the RapidJSON allocators as so: char valueBuffer[2048]; char ...
Cigogne  Eveillée's user avatar
6 votes
1 answer
8k views

how do I copy a rapidjson::value?

I'm trying to copy a rapidjson::value into a class member. error: ‘rapidjson::GenericValue<Encoding, <template-parameter-1-2> >::GenericValue(const rapidjson::GenericValue<Encoding, &...
user2741831's user avatar
  • 2,194
6 votes
1 answer
487 views

How can I keep a reference to something that gets moved?

I have something as the following using rapidjson rapidjson::Value parent; parent.SetObject(); rapidjson::Value child; child.SetObject(); parent.AddMember("child", child, document....
Lord Nikon's user avatar
5 votes
2 answers
21k views

Write in file using Rapidjson

How can i write some data into file using rapidjson document : Here is what i need to write : "Big Node ": [ { "Big Key": "Key Value 1", "Child Key": "Key Value 1", "Values"...
user avatar
5 votes
1 answer
5k views

Can I distinguish Integer and Double type in rapidjson

When I ask type of rapidjson::Value using GetType() method, it returns only belows Type: //! Type of JSON value enum Type { kNullType = 0, //!< null kFalseType = 1, //!< false ...
Jason Heo's user avatar
  • 10.1k
5 votes
2 answers
8k views

rapidjson - change key to another value

Here is the hello world of rapidjson. How can I change key "hello" to "goodbye" and get string from the json? I mean I want to parse json, change some keys and get json string back like {"goodbye" : "...
Narek's user avatar
  • 39.4k
5 votes
1 answer
9k views

C++ rapidjson: GenericValue::IsNull is returning false in any case

I still shocked after detecting a mysterious issue on our project. We realized that calling HasMember("string") was performing an extra seek. So, for performance reasons, we change it. The main idea ...
dmayola's user avatar
  • 502
5 votes
1 answer
3k views

How can I validate a subset of a RapidJSON document?

I'm using RapidJSON to parse messages that (roughly) conform to JSON-RPC. Here's an example of one such message: { "method": "increment", "params": [ { "count": 42 } ] } The content of ...
evadeflow's user avatar
  • 4,874
5 votes
2 answers
2k views

RapidJson undefined reference

in function rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::GenericDocument(rapidjson::GenericDocument<rapidjson::UTF8&...
Arvind Kanjariya's user avatar
4 votes
4 answers
21k views

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(...
Damir's user avatar
  • 55.2k
4 votes
2 answers
8k views

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's user avatar
  • 51
4 votes
4 answers
2k views

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 ...
GetFree's user avatar
  • 41.5k
4 votes
1 answer
8k views

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. ...
Alexandru Irimiea's user avatar
4 votes
3 answers
9k views

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 ...
user1583007's user avatar
4 votes
1 answer
3k views

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 ...
毕晓峰's user avatar
  • 151
4 votes
1 answer
9k views

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": [ ["2010-01-12",-0.010565362832445,-0.010432881793793,-0....
Malick's user avatar
  • 6,532
4 votes
1 answer
8k views

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 ...
soulmachine's user avatar
  • 4,075
4 votes
2 answers
2k views

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 ...
mtb's user avatar
  • 1,370
4 votes
2 answers
5k views

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's user avatar
  • 127
4 votes
2 answers
3k views

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 : ...
Arcyno's user avatar
  • 4,353
4 votes
1 answer
7k views

std::string to rapidJson object conversion

I was trying to convert one std::string to rapidJson object in below format { "data":{ "value": "AB1234" } } I have tried rapidjson::Document aJsonDocument; ...
user2235747's user avatar
4 votes
1 answer
4k views

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["...
J. Doe's user avatar
  • 97
4 votes
1 answer
13k views

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": "...
Prashant's user avatar
  • 1,178
4 votes
3 answers
4k views

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";...
Ngoc's user avatar
  • 479
4 votes
1 answer
564 views

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":"...
user7588316's user avatar
4 votes
0 answers
2k views

RapidJSON: How to move one Document to another?

I'm trying to pass a Document as a parameter (in this case to a C++ Class C'tor, but doens't really matter), and move it, so the orig Document will become Null, and the class member will hold the ...
brkeyal's user avatar
  • 1,357
4 votes
1 answer
1k views

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 ...
user3339357's user avatar
4 votes
1 answer
3k views

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 ...
Muhammad Zaighum's user avatar
3 votes
2 answers
6k views

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....
Drew Noakes's user avatar
3 votes
2 answers
7k views

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 = ...
nilan's user avatar
  • 61
3 votes
1 answer
4k views

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 ...
Cédric Verstraeten's user avatar

1
2 3 4 5
8