Skip to content

Can't parse not formatted JSON. #2340

Description

@biggerevil

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions