JsonCpp parse issue

I have created a .json file, and need to read it and append some new information to it.
This is in JsonCpp library, and I have no issue creating the new information, but when I attempt to append to the .json file, I get a LogicError related message.

Here is the actual line causing problems:

json_obj.append(root);

root is the new information, json_obj is the read in from the .json file data.

Does anyone have any suggestions on how to properly handle this, as I have additional updates to the .json related to appending to perform.

Thank you.
I'm not sure what you expect from us. Without knowing the types of json_obj and root, that line is completely meaningless.
You should create a minimal compileable example (even better if it's just using strings instead of working with files). And link the github or whatever to your library.
Json::Value is the type for both.
Our crystal balls are busted, we don't have a clue what is going on without providing us with a compileable example and a lot more information.
OP, why are you carefully choosing your words to provide the minimum information possible? Are you trying to deliberately waste our time and don't really care if your question gets answered?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <json/json.h>
#include <stdio.h>
#include <fstream>

Json::StreamWriterBuilder jswb;

char gfilename[BUFSIZ];
strcpy (gfilename, "gfile.json"); // original json file
        
std::fstream json_file;
Json::Value root(Json::arrayValue); // contains some additional json info to append
Json::Value json_obj;
json_file.open(gfilename, std::ios_base::in);    

json_file >> json_obj; // parsed json file read from file
json_file.close();
// append to json object
json_obj.append(root);
    
// write updated json object to file
json_file.open(gfilename, std::ios::out);
jswb["indentation"]="";

std::string jsonMsg = Json::writeString(jswb,json_obj) + "\n";
json_file << jsonMsg;
json_file.close();


Stilll no self-contained compileable example, as was previously and politely requested. Not SSCCE.

http://www.sscce.org/

You want suggestions....

Do what you are asked to do. Provide code we can compile, run and observe ourselves.
Topic archived. No new replies allowed.