Skip to content

Instantly share code, notes, and snippets.

@matt-42
Created April 14, 2016 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-42/def26a8f4ac7ddee7f60af4bf1aaff37 to your computer and use it in GitHub Desktop.
Save matt-42/def26a8f4ac7ddee7f60af4bf1aaff37 to your computer and use it in GitHub Desktop.
iod json parsing of nested objects
#include <iostream>
#include <iod/json.hh>
// Run iod_generate_symbols test.cc symbols.hh
#include "symbols.hh"
int main()
{
std::string str = R"({"name": "x", "position": { "x": 10, "y": 11, "z": 12}})";
using namespace s;
auto o = iod::D(_name = std::string(),
_position = iod::D(_x = int(), _y = int(), _z = int()));
json_decode(o, str);
assert(o.name == "x");
assert(o.position.x == 10);
assert(o.position.y == 11);
assert(o.position.z == 12);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment