Append to an existing array of JSON objects on file using rapidjson -


i have array of json objects similar below:

[     {"hello": "rapidjson",     "t": true,     "f": false,     "n": null,     "i": 2,     "pi": 3.1416},    {"hello": "rapidjson",     "t": true,     "f": false,     "n": null,     "i": 12,     "pi": 3.88},     {"hello": "rapidjson",     "t": true,     "f": false,     "n": null,     "i": 14,     "pi": 3.99} ] 

my application spits out bunch of json objects need add json file every 30 seconds lets say.

each round need append same file , add new json objects array of json objects have. first entry of each json file json schema.

the problem facing not know how each time read previous file , add new objects array of existing objects in file , write updated file.

could please provide me guidance needs done? or point me couple of examples (couldn't find similar example in tutorial)?

assuming current array of json objects on file is:

[{"one", "1"}, {"two", "2"}]

and want add json object --> {"three", "3"} , write same file final file looks this: [{"one", "1"}, {"two", "2"}, {"three", "3"}]

here list of complete steps take:

using namespace rapidjson;   file* fp = fopen(json_file_name.c_str(), "r");  char readbuffer[65536];  filereadstream is(fp, readbuffer, sizeof(readbuffer));   document d, d2;  d.parsestream(is);  assert(d.isarray());  fclose(fp);  d2.setobject();  value json_objects(kobjecttype);  json_objects.addmember("three", "3", d2.getallocator());  d.pushback(json_objects, d2.getallocator());   file* outfile = fopen(json_file_name.c_str(), "w");  char writebuffer[65536];  filewritestream os(outfile, writebuffer, sizeof(writebuffer));   writer<filewritestream> writer(os);  d.accept (writer);  fclose(outfile); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -