-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
How to validate an input before parsing? #1336
Comments
You can use the |
Thanks, that works great for the case in which I am validating if I have good JSON. Now I just ran into the problem in which I need to validate that I have a JSON field "action" I tried to use: string action = body["action"];
if (action.empty()) {
cout << "Action NULL" << endl;
} else {
cout << "Action GOOD" << endl;
} just as a test since if I send a json like: {"test":"test"} then I get.
Basically, I want to now cover the case in which I have good JSON but not the correct fields {"action" : "test" } would be good. How can I check for this? |
|
(If you want to check against |
Thanks for your help. I was able to get things working with is_null() and find() |
Hello,
I am working on an API type project which will receive JSON string requests. I need to validate that the input string is a good JSON string before parsing it.
I thought that I saw something in my nlohmann searching that suggests that something was going to be, or is now already, integrated into the library.
Could you please tell me where to get more information on this and possibly a simple example, as the "try-catch" method does not seem to work well for me.
Thanks :)
The text was updated successfully, but these errors were encountered: