How do you get a JSON object from a string in nlohmann json? How do you get a JSON object from a string in nlohmann json? json json

How do you get a JSON object from a string in nlohmann json?


Adding _json to a string literal instructs the compiler to interpret it as a JSON literal instead.

Obviously, a JSON object can equal a JSON value, but a string cannot.

In this cases, you have to remove _json from the literal, but that makes second a string value hiding inside a JSON object.

So, you also use json::parse, like this:

std::string s = "[\"nlohmann\", \"json\"]";json second = json::parse(s);

How to create a JSON object from a string.