Imagine a data.json file with the following content:

  "text": "foobarism",
  "life": 42
The syntax is as follows:

JsonValue value = JsonValue::from_json(File::read_text("data.json"));

std::string text = value["text"];
int life = value["life"];

value["text"] = text + " on and on!";
value["life"] = life * 2;

File::write_text("data2.json", value.to_json());
The code outputs a new data2.json file with:

  "text": "foobarism on and on!",
  "life": 84
Note that the JsonValue class got a few outstanding issues:

  • Some of the operator= functions are missing the C++11 explicit keyword to prevent 'int' and 'bool' matching 'std::string'
  • Same thing for operator bool() const and operator int() const
  • JsonValue::read_string does not support unicode escapes yet. You will probably have to fix this if you want to use this class for anything serious.
  • JsonValue::write_string does not escape strings yet. This also has to be fixed.

Unless someone volunteers to fix these 4 issues I can't really recommend using the JsonValue class at this time.