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() fails to parse a dump(2,' ') output, yet does successfully parse dump() #2105

Closed
phillatwood opened this issue May 13, 2020 · 3 comments
Labels
solution: invalid the issue is not related to the library

Comments

@phillatwood
Copy link

See the attached json dump output files.
dump_compact.txt
dump_pretty.txt

Both of these files are the result of dumping the exact same json object. I expected both to be successfully parsed. However, the file dump_pretty.txt, which was the result of dump(2,' '), throws the following parse error :

[json.exception.parse_error.101] parse error at line 240041, column 5: syntax error while parsing value - unexpected string literal; expected end of input

and yet the same json object dumped with the call dump() did successfully parse without throwing any error. See dump_compact.txt.

I'm using MSVC 2019 Version 16.5.4

I'm using JSON for Modern C++ 3.7.3 single header json.hpp

Thanks for your help in advance.

@nlohmann
Copy link
Owner

Both files are valid JSON. The error message is odd, as line 240041 only contains of a single } character. Maybe the file was not read correctly. Can you share the code with that parsed the files?

This is what I tried:

#include <iostream>
#include <iomanip>
#include <fstream>
#include "json.hpp"

using json = nlohmann::json;

int main()
{
    std::ifstream pretty("/Users/niels/Downloads/dump_pretty.txt");
    std::ifstream compact("/Users/niels/Downloads/dump_compact.txt");
    
    json p = json::parse(pretty);
    json c = json::parse(compact);
    
    std::cout << "JSON objects are equal: " << std::boolalpha << (p == c) << std::endl;
}

Output:

JSON objects are equal: true

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label May 13, 2020
@phillatwood
Copy link
Author

phillatwood commented May 13, 2020 via email

@nlohmann
Copy link
Owner

Thanks for reporting back!

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug state: needs more info the author of the issue needs to provide more details labels May 14, 2020
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