I'm using the following code right now:
json customers;
for (...)
{
customers.push_back(...)
}
cout << customers;
However, if the for loop doesnt happen, I would like to return an empty array (eg [])
Is they an other way to get this behaviour without doing json customers= json::parse("[]"); ?
I assume this is fixed by fixing #8
@Teemperor is right - this shall be fixed with issue #8. I hope to do this by tomorrow.
So far, you could try
json customers(json::value_type::array);
to tell the class to create an empty JSON array.
There now is a function json::array() to create an empty array. It can also be used with an initializer list (e.g., json::array({"foo", "bar"})) to explicitly create the array ["foo", "bar"] rather than the object {"foo": "bar"}.
Most helpful comment
There now is a function
json::array()to create an empty array. It can also be used with an initializer list (e.g.,json::array({"foo", "bar"})) to explicitly create the array["foo", "bar"]rather than the object{"foo": "bar"}.