Skip to content
JsonData

Render

std::string Render(const bool minify = false) const

Will render this JsonData (and thus its whole tree) recursively and return the result.

If minifiy is true, it will render without linebreaks and unnecessary spaces. Essentially minified ;).

I want my render sorted by labels!

No problemo, just define JASONPP_RENDER_SORTED as a preprocessor definition.

Example

Setup

Json json = Json(JsonBlock()); // Json is just a typedef for JsonData
json["name"] = "Peter Griffin";
json["age"]  = 58,
json["kids"] = Arr{ "Stewie", "Chris", "Megatron" };

Return values:

json.Render()

{
  "name": "Peter Griffin",
  "age": 58,
  "kids": [
    "Stewie",
    "Chris",
    "Megatron"
  ]
}

json.Render(true)

{"name":"Peter Griffin","age":58,"kids":["Stewie","Chris","Megatron"]}

Aliases

Alternative ways to call this function

Only, if

Only if myJsonData is not of json type STRING!

Pretty or minified render

Use JASONPP_STRINGCONV_MINIFY to control whether or not "string to render" conversions render pretty, or minified.
It renders pretty by default.

  • std::string str = myJsonData;
  • std::cout << myJsonData << std::endl;