New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"_json" user defined string-literal suffix #1994
Comments
Hi @hattesen, I already considered adding the The first is that it hides a call to The second reason is that, unlike nlohmann's library, ArduinoJson doesn't throw exceptions, so I don't have any way to report an error if anything goes wrong with the deserialization. Best regards, |
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 aJsonDocument
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:
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).
The text was updated successfully, but these errors were encountered: