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

Library Cannot Parse JSON File It Wrote #4448

Open
2 tasks
JohnFayGeezer opened this issue Sep 4, 2024 · 1 comment
Open
2 tasks

Library Cannot Parse JSON File It Wrote #4448

JohnFayGeezer opened this issue Sep 4, 2024 · 1 comment
Labels
solution: invalid the issue is not related to the library solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@JohnFayGeezer
Copy link

Description

I used the JSON library to "pretty-print" a JSON file. I then read that JSON file into a character array variable and the parser terminated on error. This has happened with several JSON files; I am submitting a minimal example.

Reproduction steps

I created the following file named "minimal.json" using Notepad++ on Windows. It contains four lines, including a blank last line:

{
"LABEL": 0.0
}

I then wrote the attached C++ program and built it using Cygwin.

g++ -g -DLINUX -Ijson/single_include json_test.cpp

I ran the executable with no command line inputs so that it read "minimal.json" and wrote "min_output.json". I then renamed "min_output.json" to "minimal_BadChar.json" and ran the program again, this time with a command line argument so that it read this file. The parser terminated on error with a message about an invalid input.

minimal.json
minimal_badChar.json
json_test.cpp.txt

Expected vs. actual results

I would expect the code to be able to read a file that it wrote.

Minimal code example

See files attached earlier.

Error messages

terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_3::detail::parse_error'
  what():  [json.exception.parse_error.101] parse error at line 4, column 1: syntax error while parsing value - invalid literal; last read: '0.0<U+000A>}<U+000A>'; expected end of input

Compiler and operating system

Cyrwin g++ 11.3.0

Library version

3.11.3

Validation

@gregmarr
Copy link
Contributor

gregmarr commented Sep 4, 2024

Looks like you wrote the string in ASCII mode so it was written with newlines as \r\n and then read it in binary mode, so the \r was kept.

@nlohmann nlohmann added solution: invalid the issue is not related to the library solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed kind: bug labels Sep 13, 2024
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 solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

4 participants
@nlohmann @gregmarr @JohnFayGeezer and others