Questions tagged [jsoncpp]

jsoncpp is an open source JSON reader and writer for C++

jsoncpp is an implementation of a JSON reader and writer in C++. JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

318 questions
55
votes
9 answers

Reading json files in C++

I'm trying to read in a JSON file. So far I have focused on using the jsoncpp library. However, the documentation is quite hard to understand for me. Could anyone explain in lay terms what it does? Say I have a people.json which looks like…
user3515814
  • 957
  • 2
  • 8
  • 13
53
votes
6 answers

Converting a Json::Value to std::string?

I am using JsonCpp to build a JSON object. Once the object is built, is there a way I can get the object as an std::string?
BRabbit27
  • 6,333
  • 17
  • 90
  • 161
31
votes
5 answers

Iterating through objects in JsonCpp

I have a C++ application that uses jsoncpp to decode a JSON string. I have created the following function but it only shows me the top level objects... How do I get it to dump the entire object list? --Function-- SaveJSON( json_data ); bool…
Steven Smethurst
  • 4,495
  • 15
  • 55
  • 92
26
votes
5 answers

JSONCPP Writing to files

JSONCPP has a writer, but all it seems to do is get info from the parser and then output it into a string or a stream. How do I make it alter or create new objects, arrays, values, strings, et cetera and write them into the file?
Yelnats
  • 489
  • 2
  • 6
  • 9
24
votes
3 answers

Json-cpp - how to initialize from string and get string value?

My code below crashes(Debug Error! R6010 abort() has been called). Can you help me? I'd also would like to know how to initialize the json object from a string value. Json::Value obj; obj["test"] = 5; obj["testsd"] = 655; string c = obj.asString();
Greyshack
  • 1,901
  • 7
  • 29
  • 48
21
votes
3 answers

Create empty json array with jsoncpp

I have the following code: void MyClass::myMethod(Json::Value& jsonValue_ref) { for (int i = 0; i <= m_stringList.size(); i++) { if (m_boolMarkerList[i]) { jsonValue_ref.append(stringList[i]); } …
Martin Meeser
  • 2,784
  • 2
  • 28
  • 41
17
votes
1 answer

Compiling and Using JSONCPP on Visual Studio10 with Boost

I have recently compiled the SVN version of JSONCPP using the VS71 makefiles. It worked, but I get a lot of linker errors 1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __int64 __thiscall std::basic_streambuf
Yelnats
  • 335
  • 1
  • 3
  • 7
16
votes
2 answers

Parsing JSON string with jsoncpp

I'm trying to parse a JSON string encoded with PHP and sent over TCP to a C++ client. My JSON strings are like this: {"1":{"name":"MIKE","surname":"TAYLOR"},"2":{"name":"TOM","surname":"JERRY"}} On the C++ client I'm using the jsoncpp…
Podarce
  • 473
  • 1
  • 6
  • 22
12
votes
2 answers

Is there an elegant way to cascade-merge two JSON trees using jsoncpp?

I am using jsoncpp to read settings from a JSON file. I would like to have two cascading settings file, say MasterSettings.json and LocalSettings.json where LocalSettings is a subset of MasterSettings. I would like to load MasterSettings first and…
Tim MB
  • 4,413
  • 4
  • 38
  • 48
11
votes
5 answers

How to read a JSON file containing multiple root elements?

If I had a file whose contents looked like: {"one": 1} {"two": 2} I could simply parse each separate line as a separate JSON object (using JsonCpp). But what if the structure of the file was less convenient like this: { "one":1 } { …
tshepang
  • 12,111
  • 21
  • 91
  • 136
10
votes
2 answers

jsoncpp how to check if tag is null .isNull() throw assertion

Im using jsoncpp , its great but when i need to check if json structure contains tag when i do it with : UserRoot0["error"].isNull() its throws me assert from json_value.cpp line 1025 JSON_ASSERT( type_ == nullValue || type_ == objectValue ); i…
user63898
  • 29,839
  • 85
  • 272
  • 514
10
votes
3 answers

jsoncpp formatting problems

I'm using jsoncpp and I'm having a problem with how the json messages are formatted when they are written using one of the Writers. For example: root["name"] = "monkey"; std::cout << writer.write(root) << "\n"; Gives me something formatted like…
KaiserJohaan
  • 9,028
  • 20
  • 112
  • 199
10
votes
2 answers

Fatal error with jsoncpp while compiling

Am new to cpp but as per project requirements i need to consume rest api and parse the response. Am able to call api & capture the response but not able to parse it using JSONCPP library. These are the steps i followed to parse json: Used this…
Nevin
  • 169
  • 1
  • 2
  • 7
10
votes
3 answers

Jsoncpp writing float values incorrectly

I am reading from a JSON file using jsoncpp. When I write back to the file, my float values are slightly off. For the sake of testing, I decided to parse the file to a Json::Value and then write that value back to the file. I would expect it to look…
SFBA26
  • 870
  • 3
  • 12
  • 24
10
votes
2 answers

JsonCpp - when having a json::Value object, how can i know it's key name?

Let suppose I have this Json file: [ { "id": 0 } ] using jsoncpp, i can have a Json::Value object by doing this: Json::Value node = root[0u]["id"]; OK, somewhere else in the code, I'm getting that node object, and I want to get…
Rong
  • 103
  • 1
  • 1
  • 6
1
2 3
21 22