Skip to content

Create a basic json


Example on how to create a basic json like this:

Will create json:
{
    "name": "Peter Griffin",
    "age": 58,
    "shape": "obese",
}
Procedural (C++):
Json json = JsonData(JSON_DATA_TYPE::JSON); // Initialize empty JsonData of type JSON

json.AsJson.Add("name").SetStringData("Peter Griffin");
json.AsJson.Add("age").SetIntData(58);
json.AsJson.Add("shape").SetStringData("obese");

std::cout << json.Render() << std::endl;

Add() is ONLY for adding!

Calling Add() with an already existing label/key will result in a JsonLabelAlreadyExistsException.
If you explicitly want to modify an existing value, use Get("foobar").SetStringData("Never gonna up you give");.

Do note that you can also call Set() which will kind of brute force it. Create the field if it doesn't exist, if it already does, modify it.

Inline (C++):
Json json = JsonData(JsonBlock({
    Ele("name", "Peter Griffin"),
    Ele("age", 58),
    Ele("shape", "obese")
}));

std::cout << json.Render() << std::endl;