Skip to main content
added 169 characters in body
Source Link

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"
  }
}

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?

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"
  }
}
Source Link

How to add one JsonDocument to another in ArduinoJson

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?