-
-
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
Failing to Parse Valid JSON #2209
Comments
I cannot reproduce the issue with the same compiler.
Full code for reference (using develop branch 29ad217): #include <iostream>
#include "json.hpp"
using json = nlohmann::json;
int main() {
std::string jsonStr = R"({ "key": [ { "id": "this_is_a_string", "color": { "r": 125, "g": 23, "b": 78 } } ] })";
auto j = json::parse(jsonStr);
std::cout << j << std::endl;
} Output: {"key":[{"color":{"b":78,"g":23,"r":125},"id":"this_is_a_string"}]} Can you please double check your code? |
I ran that exact code and got the same error... very strange! Let me try with that specific branch. |
Can you try to execute the unit tests? |
My "develop" was old. Works as expected with latest version. Thank you :) |
Thanks for checking back! |
I get the same error on version 3.7.3 ...
|
The library will accept any valid JSON as long as it’s UTF-8 encoded. Can you copy the exact input and the code you use to parse it? |
Sorry, I can't provide the specific data, because I chunked a large file and called JSON:: parse to serialize it. I found this error in the log file, and I found that the error is not deterministic, even if the same input data. I will continue to test it with other third-party JSON libraries, and I will reply in time whether there is an error in my program itself or the cause of JSON:: parse. |
If it’s nondeterministic, maybe you pass an invalid input buffer. Try running it with ASAN. |
I will |
It's my mistake , I mistakenly used the network library, resulting in a message error. |
The library fails to parse seemingly-valid JSON
What is the issue you have?
This code snippet:
Fails with:
What is the expected behavior?
No error to be thrown; the JSON is apparently valid:
https://jsonlint.com/?json={%20%22key%22:%20[%20{%20%22id%22:%20%22this_is_a_string%22,%20%22color%22:%20{%20%22r%22:%20125,%20%22g%22:%2023,%20%22b%22:%2078%20}%20}%20]%20}
And what is the actual behavior instead?
A crash, seemingly when parsing the integers -- it works when the integers are quoted.
Which compiler and operating system are you using?
OSX, with
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
The text was updated successfully, but these errors were encountered: