json
json copied to clipboard
No simple way to parse from std::istream
There should be a quick and convenient way to parse JSON from std::istream
. E.g.
std::ifstream f("path/to/file");
auto jv = json::parse(f);
there should be parse_istream and there should even be parse_file that takes the file name directly
Well, parse_istream
can just be a parse
overload.
We have operator<<
for serializing but no operator>>
for parsing
It's be great to have
std::istringstream iss{"[1,2,3,4,5]"};
value jv;
iss >> jv;
@prince-chrismc I agree! Would you like to try your hand at it? Shouldn't be too hard...
I have a blueprint for the fix. I originally wanted to make the streambuffer to put all input into parser as soon as possible which would work OK with something like istream >> &json_buffer
. But then I realized that
std::copy(
std::istreambuf_iterator<char>(istream),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterparsing(&json_buffer))
will push input into parser one byte a time, which is very ineffective. So, my approach has to be changed to have a proper buffer in the streambuf.