I'm utilizing this json library: https://arduinojson.org/
I am attempting to write a function that creates a response object, and wraps an already built json document:
void sendResponse(
ResponseType state,
JsonDocument *response
) {
DynamicJsonDocument doc(256);
doc[F("state")] = responseTypeFromEnum(state);
doc[F("response")] = response; //breaks; how to do?
this->sendJson(&doc);
}
This fails of course, and I don't see a great solution anywhere...
I know I could use createNestedObject(), but this seems to require re-creating the given json object by hand? This would be a sub-optimal case.
Is there a way to easily wrap an existing JsonDocument in another?
Looking to take
{
"some": "other document"
}
And wrap it like
{
"state":"OK"
"response": {
"some": "other document"
}
}