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

Crash when parse big jsonfile #2042

Closed
oskycar opened this issue Apr 15, 2020 · 7 comments
Closed

Crash when parse big jsonfile #2042

oskycar opened this issue Apr 15, 2020 · 7 comments
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@oskycar
Copy link

oskycar commented Apr 15, 2020

  • What is the issue you have?
    I had gened a 5.8M json file. when I parse it use nlohmann/json, it crashed!.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

nlohmann::json jobj = nlohmann::json::parse(file);

  • Which compiler and operating system are you using? Is it a supported compiler?
    MacOS 10.15.3, Use Xcode 11.3.1

  • Did you use a released version of the library or the version from the develop branch?
    use released version 3.6.1, I also tried latesed version 3.7.3, it crashed too.

  • If you experience a compilation error: can you compile and run the unit tests?

the output error message:
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 - invalid literal; last read: '/'

I had upload the json file url: https://www.dropbox.com/s/5wsfcd6p06jeckk/out.json?dl=0

@nlohmann
Copy link
Owner

Are you sure it is exactly that file? The parser error states that there was a / read. Can you make sure the file is read from the beginning?

@oskycar
Copy link
Author

oskycar commented Apr 16, 2020

Are you sure it is exactly that file? The parser error states that there was a / read. Can you make sure the file is read from the beginning?

o...,maybe I made a mistake, I passed the file path to it, like this:
nlohmann::json jobj = nlohmann::json::parse("/tmp/a.json");

when I follow the example code, It works very well.
std::ifstream i("/Users/allenyang/Desktop/out.json"); nlohmann::json j; i >> j;

so It can only pass the file content to it ?

@ArtemSarmini
Copy link
Contributor

This function expects a string to parse, not a path to some file.

@nlohmann
Copy link
Owner

You can pass an std::ifstream to the parse function to read from a file. If you pass a string, it is interpreted as JSON text, not as a filename.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Apr 16, 2020
@nlohmann
Copy link
Owner

@oskycar Do you need further assistance?

@oskycar
Copy link
Author

oskycar commented Apr 16, 2020

@oskycar Do you need further assistance?

thank you very much. I had no more questions.

@oskycar
Copy link
Author

oskycar commented Apr 16, 2020

@oskycar Do you need further assistance?

we can close this issue. Thanks for your attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants