You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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;
intmain()
{
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;
}
Okay, thanks for your very prompt help. Yes, it is a file read problem
after all. So nothing wrong with the json::dump() / json::parse(). I was
thinking there could be a json issue because other files I was dump()ing
and parse()ing were working fine ...
Thanks for looking into it just the same. I really appreciate it.
Just in case you are wondering, below is my file reading code. This is the
corrected version that reads and parses properly. The version that failed
is the same except the first line changes as indicated by the comment.
Probably some subtleties with \r\n newlines?.
CFile file; // CStdioFile file; fails
if (!file.Open(filename, CFile::modeRead | CFile::shareDenyWrite))
return false;
int len = (int)file.GetLength();
std::string entire_file;
entire_file.resize(len);
file.Read(entire_file.data(), len);
file.Close();
json jall = json::parse(entire_file);
Phill Atwood
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.
The text was updated successfully, but these errors were encountered: