To pretty-print JSON, read it to json_value object and save to the output stream with format() manipulator.
json_value
format()
Code:
#include <string> #include <sstream> #include <cpp-json-qi/json.h> std::string input("....") std::istringstream iss(input); jsonqi::json_value val; iss >> val; std::ostringstream oss; oss << jsonqi::format() << jsonqi::json_value(val);
input JSON:
{"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"} ] } }}
output JSON:
{ "menu": { "id": "file", "popup": { "menuitem": [ { "onclick": "CreateNewDoc()", "value": "New" }, { "onclick": "OpenDoc()", "value": "Open" }, { "onclick": "CloseDoc()", "value": "Close" } ] }, "value": "File" } }
There was an error while loading. Please reload this page.