std_data_json icon indicating copy to clipboard operation
std_data_json copied to clipboard

parseJSONStream() requires ForwardRanges

Open ylegall opened this issue 8 years ago • 1 comments

The signature of parseJSONStream() constrains the input type to InputRange, but it seems like it actually requires a ForwardRange due to the calls to std.algorithm.skipOver() in lexer.d.

I was trying to call parseJSONStream() on a range of ubyte from a file (without reading the entire file into memory), using the basic approach:

auto fileRange = File("input.json").byChunk(4096).joiner;
auto tokens = parseJSONStream(fileRange);

This fails with a type error: std_data_json-0.18.2/std_data_json/source/stdx/data/json/lexer.d(341,29): Error: template std.algorithm.searching.skipOver cannot deduce function from argument types !()(Result, string)

Is there better way to do this? Probably at the least, the template constraints for parseJSONStream() should be changed to ForwardRange, but support for InputRanges would allow incremental parsing from a file.

Also, here is a related open forum thread: http://forum.dlang.org/thread/[email protected]

ylegall avatar Sep 17 '17 02:09 ylegall

It seems like it also doesn't work well with ubyte input stream, i.e. the result from vibe.d's request/response bodyReader()

marcioapm avatar Jul 24 '18 21:07 marcioapm