Hi,
I have json payloads to process which are 80% similar. However, one field - let's say "animal" - is different in each case.
{
"p": "some text",
"n": 1234,
"animal": { "age": 12, "name": "cat"}
}
Or sometimes as
{
"p": "some text",
"n": 1234,
"animal": { "says": "bowwow", "name": "dog"}
}
What's a clean (and simple) way to deserialize this object? I was hoping to do this, but it fails:
struct MyResponse {
string p;
int n;
Json animal;
}
auto res = deserializeJson!MyResponse(stringFromCurl);
I also tried a template, but I've had trouble getting the logic to flow. In one method I keep getting stuck with the compile error Error: variable r cannot be read at compile time
struct MyResponse(T) {
string p;
int n;
T animal;
}
struct Cat {
string name;
int age;
}
auto res = deserializeJson!(MyResponse!Cat(stringFromCurl));