-
-
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
unable to parse json #1525
Comments
Have you tried printing out the text after opening the stream? You appear to have some sort of garbage before the first character. |
It prints fine: std::cout << jsonFile.rdbuf() << std::endl; |
Could you please share the file? |
I have attached the file (I changed the extension from json to txt). |
Hm. This all looks good: #include "json.hpp"
#include <iostream>
#include <fstream>
using json = nlohmann::json;
int main() {
std::ifstream f("/Users/niels/Downloads/appTest.txt");
json j = json::parse(f);
std::cout << j << std::endl;
} produces {"default":"sometext"} |
@somequery Can you try the exact program of #1525 (comment) (well, with a different path...)? |
I used the full path as you mentioned, but the result is the same. I run it from VS and from a command line also, from the directory containing both the out and json file. I've received the same error always. |
After rebuilding it now works. But there is still problem (with the same error) on nlohmann::json parsed_json = nlohmann::json::parse(f); Am I doing wrong something? |
Does it mean you can parse the file successfully now?
What is the problem? |
and
I figured out that I should be using the first or the second way but not both together. So everything works now. Thanks. |
Thanks for clarifying! |
Hi, I'm having parse_error.101 as well. I went through a bunch of reported issues about this but none of the suggested solutions seem to have solve my issue: I checked the encoding and made sure it's UTF8, I tried to use the full file path, I checked the bytes with Bless hex editor and everything seems to be in place. Here is the exact program I'm using:
This is the .json file I'm using with its extension modified to .txt: example_1.txt Here is the output of the program:
I'm working on Ubuntu 16.04, compiling in a Catkin workspace. |
You read the entire file and print it out, so there's nothing left to parse in the stream. What happens if you don't do that read and print first? |
Thanks for the tip @gregmarr ! You are right and this actually solved the issue!.. Much kudos! |
You're welcome. |
I am parsing the json file:
{
"default_txt": "sometext"
}
C++ code:
std::ifstream jsonFile("appTest.json", std::ios::in);
nlohmann::json parsed_json = nlohmann::json::parse(jsonFile);
I get an error:
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
I tried:
1/ full path name instead of just the file name
2/ I have checked the json formatting in online parsers with success
3/ parsed successfully with boost property tree
Do yo have any suggestions?
Thanks.
The text was updated successfully, but these errors were encountered: