dlang-community / std_data_json

Phobos candidate JSON implementation.
25 stars 13 forks source link

Why parseJSONValue accept only reference? #28

Closed bubnenkoff closed 8 years ago

bubnenkoff commented 8 years ago

"String is a valid range, but parseJSONValue takes a reference to a range, because it directly consumes the range and leaves anything that appears after the JSON value in the range. toJSON() on the other hand assumes that the JSON value occupies the whole input range." you wrote this answer on forum.dlang.org when I asked about why function do not accept strings.

But what problem is to add strings? Could you explain please

s-ludwig commented 8 years ago

toJSONValue is the function that you are looking for. The difference is that parse only parses up to the end of the first JSON "value" that it finds ("value" meaning literal, object or array), leaving the rest of the input range untouched. to on the other hand assumes and enforces that the complete input string only contains a single value. The naming was chosen to be in line with std.conv. However, this issue has been brought up a number of times now, so obviously it isn't very intuitive.

s-ludwig commented 8 years ago

I'll close this as a duplicate of #14 and keep that open.