Create empty json array with jsoncpp

You can do this by defining the Value object as an "Array object" (by default it makes it as an "object" object which is why your member becomes "null" when no assignment made, instead of [] )

So, switch this line:

 Json::Value jsonValue;
 myMethod(jsonValue);

with this:

Json::Value jsonValue(Json::arrayValue);
myMethod(jsonValue);

And voila! Note that you can change "arrayValue" to any type you want (object, string, array, int etc.) to make an object of that type. As I said before, the default one is "object".


Here are two ways you can do it:

jsonRootValue["emptyArray"] = Json::Value(Json::arrayValue);
// or 
jsonRootValue["emptyArray"] = Json::arrayValue;

Tags:

C++

Json

Jsoncpp