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

json::parse() works only with absolute paths #2851

Closed
wiljam144 opened this issue Jul 6, 2021 · 2 comments
Closed

json::parse() works only with absolute paths #2851

wiljam144 opened this issue Jul 6, 2021 · 2 comments
Labels
solution: invalid the issue is not related to the library

Comments

@wiljam144
Copy link

So when i'm trying to read from a json file everything works fine with absolute paths but when i pass relative path the program crashes with this error message:

terminate called after throwing an instance of 'nlohmann::detail::parse_error'
  what():  [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
make: *** [Makefile:2: start] Error 3

the function code:

json loadFile(string filename) {
    ifstream ifs(filename);
    json data = json::parse(ifs);
    ifs.close();
    return data;
}
@nlohmann
Copy link
Owner

nlohmann commented Jul 6, 2021

unexpected end of input means the that no input could be read - this is not a bug in the library, but just an indication that the file could not be read in the first place. Please make sure the working directory is correct. Maybe try to dump the file content to stdout without calling parse first.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels Jul 6, 2021
@wiljam144
Copy link
Author

makefile i wrote contained a command to compile the whole project that was outputting the binary to the wrong directory after making changes to the makefile everything worked just fine

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

2 participants