-
-
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
Unexpected end of input; expected '[', '{', or a literal #2066
Comments
Can you double check that the file was successfully opened and that you could read its contents (e.g., by just printing it to cout)? |
Thanks for the speedy reply. So:
Produces no output, while:
prints out perfectly. (And i must have not tested before for some reason, but with absolute path As I say though, on windows it just works with rel paths, and for my application I think i'd really prefer them. |
As I am writing this, I am also struggling with relative/absolute paths in a project ;-) Good to know this works now. Do you need further assistance? |
If this is a known issue/not considered an issue then no, thanks a lot for the help once again. |
It's not an issue of the library - it assumes a correctly opened stream to read from. |
Hello! Same problem. Can't understand why. I'm using the code of official doc. #include <fstream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
// ...
std::ifstream f("example.json");
json data = json::parse(f); |
Most likely, Note that you can not both print the file contents and parse it without extra work in between, so just do one run to make sure that you're getting the file, and don't do any of the parsing, and then remove the extra code for verifying the output and do the parsing. |
In my case the "problem" was the executable location, which is in project_root/cmake-build-debug, so if I have my json files in a json folder the relative path will be ../json/file.json (you have to move up the folder). Special thanks to @jack23247 |
Hello to everyone
|
This is your problem, you're reading all the data, leaving nothing for the JSON library to read.
|
I'm annoyed I couldn't find a way to fix this myself becaise I feel like I am missing something obvious.
Put simply I am getting this error:
I am trying to parse an ifstream into a json object, and have tried many ways including:
but also inlining the string, doing
json j; i >> j;
, and probably some other combinations of the same thing.I'm on WSL using Ubuntu 18.04.3 LTS with g++7.4 (I want to get that high for various other reasons... but CMake isn't playing ball) and a host of Windows 10.
All variations of the above code snippet have worked perfectrly when I run on Windows with MSVC 19.25.28614.0... But Linux just doesn't??
I also tried an absolute path, didn't seem to help. I was able to read in the file fine on Linux with an ifstream, but json still threw this error.
I checked the file itself too. It most certainly does start with
{
, otherwise Windows would have cried too. The line endings are UNIX and there is no hidden BOM at the top. For the sake of completeness here is what it looks like:Finally I pulled the project in to my work as a git submodule and am using
PRIVATE nlohmann_json::nlohmann_json
with all the recommended extras, like turning tests off.Any help would be appreciated.
The text was updated successfully, but these errors were encountered: