-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add JSON validation only? #1833
Comments
Hi @Jeroen88, I repeatedly stated that I didn't plan to add a JSON validation feature to ArduinoJson. The reason I don't plan on adding this feature is that the parser is relatively lax.
It also allows syntaxes that are not supported by JSON, namely:
(although, this will probably move into a new The workaround you found is excellent! While skipping the values, the I suggest we keep this issue open to collect some feedback. Best regards, |
Hi Benoit, Thank you for your excellent answers! That is really appreciated. Sorry for not checking all the issues, although I did a search for similar questions. Also thanks for the explanation of how the parsing is done with an empty filter, now I know what to expect of the call: not perfect but good enough. It would be nice if you add the suggestion to the "How to" section! Best regards, Jeroen |
Here is the new page: How to validate a JSON document? |
Very nice and thanks for the reference! One typo in the text:
|
Hi there, I was to raise issue but found commenting here is better I have a problem in validating Json, as it returns true always: MVCE (: #include "ArduinoJson.h"
bool validateJson(const char* input) {
StaticJsonDocument<0> doc, filter;
return deserializeJson(doc, input, DeserializationOption::Filter(filter)) == DeserializationError::Ok;
}
void setup(){
char data[] = "HelloWorld";
Serial.printf("validateJson(%s) --> %d\n", data, validateJson(data));
} Output:
Tested with ArduinoJson version 6.19.4 |
Thanks for reporting this, @HamzaHajeir. I updated the website to make it more evident that this solution is not bulletproof, but your comment makes me wonder what this function is good for if it cannot detect such an obvious mistake. Honestly, I think I should remove it from the documentation. |
No problem @bblanchon, I'm wondering whether there's an effective way of checking the validity of a JSON object around? Best, |
If the |
Is your feature request related to a problem? Please describe.
Not a problem. just a useful function..
Describe the solution you'd like
A function
DeserializationError error = deserializeJson(json)
that just reports if the input JSON is a valid JSON.Describe alternatives you've considered
I do:
and that does exactly what I want. But I depend on undefined semantics: keys not present in the filter might as well be skipped instead of parsed, but it seems they are parsed too.
Additional context
None. It is not a big deal, the above alternative is also OK.
The text was updated successfully, but these errors were encountered: