Skip to content
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

Can't parse not formatted JSON. #2340

Closed
biggerevil opened this issue Aug 5, 2020 · 4 comments
Closed

Can't parse not formatted JSON. #2340

biggerevil opened this issue Aug 5, 2020 · 4 comments
Labels
solution: invalid the issue is not related to the library

Comments

@biggerevil
Copy link

biggerevil commented Aug 5, 2020

Update: The problem was I didn't close file after downloading JSON. You need to close file at first and only then parse with nlohmann.

I'm trying to parse JSON in C++ with nlohmann/json library. But this library can't parse not formatted JSON.
It gives error:
libc++abi.dylib: terminating with uncaught exception of type nlohmann::detail::parse_error: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal

This JSON gives error:

Update: here was json

But nlohmann works fine with JSON like this:

Update:  here was another json

Is there a way to format JSON from first format to the second one in C++ code? Without using websites. Maybe there's a library for this, or it's achievable with just C++ or STL.

Update: The problem was I didn't close file after downloading JSON. You need to close file at first and only then parse with nlohmann. The same what I wrote in the beginning of this comment. Just in case somebody misses it.

@nlohmann
Copy link
Owner

nlohmann commented Aug 5, 2020

The error message

[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal

states that no input could be read. Can you share the code you use to parse the input? It seems as if the file could not be opened correctly.

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Aug 5, 2020
@biggerevil
Copy link
Author

biggerevil commented Aug 5, 2020

I'm sorry, my bad. I download the needed JSON and the problem is somehow connected with that. Everything works when I try to parse already existing file (which I've downloaded a while ago).

@biggerevil
Copy link
Author

If somebody interested - I should've close the file into which I was downloading JSON data. And only after closing I parse with nlohmann.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug state: needs more info the author of the issue needs to provide more details labels Aug 6, 2020
@rubycho
Copy link

rubycho commented Sep 18, 2020

@biggerevil
Thanks. I had a similar problem; when downloading json data with CURL and parse it using the same file pointer, caused the error.
Closing and reopening with fopen solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

3 participants