Skip to content

"_json" user defined string-literal suffix #1994

Open
@hattesen

Description

@hattesen

Adding a _json user defined string-literal suffix to ArduinoJson would provide a cleaner and more declarative source code at virtually no cost, and allow a JsonDocument to be created from a JSON string literal in one line of source code.

Example (from the current ArduinoJson documentation), generating a JsonDocument from a JSON string literal:

const char* json = "{\"hello\":\"world\"}";
JsonDocument doc;
deserializeJson(doc, json);

With a _json user defined string-literal suffix, this following source code would be functionally equivalent:

JsonDocument doc = "{\"hello\":\"world\"}"_json;

It removes all the boilerplate code when parsing (unmarshalling, deserializing) a literal JSON string. It would furthermore possibly allow the parsing to be performed at compile time, since all the required resources are available then.

Using a raw string literal for the JSON string literal, would make the example even simpler on the eye (and easier to type):

JsonDocument doc = R"({"hello":"world"})"_json;

This feature would add no additional runtime cost, would be fully backward compatible, and would not require much time to implement (I believe).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions