parseJSONValue

Consumes a single JSON value from the input range and returns the result as a JSONValue.

The input string must start with a valid JSON document. Any characters occurring after this document will be left in the input range. Use toJSONValue instead if you wish to perform a normal string to JSONValue conversion.

  1. JSONValue parseJSONValue(Input input, string filename, int maxDepth)
    parseJSONValue
    (
    Input
    )
    (
    ref Input input
    ,
    string filename = ""
    ,)
    if (
    isInputRange!Input &&
    (
    isSomeChar!(ElementType!Input) ||
    isIntegral!(ElementType!Input)
    )
    )
  2. JSONValue parseJSONValue(Input tokens, int maxDepth)

Examples

Parse an object

// parse an object
string str = `{"a": true, "b": "test"}`;
JSONValue v = parseJSONValue(str);
assert(!str.length); // the input has been consumed

auto obj = v.get!(JSONValue[string]);
assert(obj.length == 2);
assert(obj["a"] == true);
assert(obj["b"] == "test");

Parse multiple consecutive values

string str = `1.0 2.0`;
JSONValue v1 = parseJSONValue(str);
assert(v1 == 1.0);
assert(str == `2.0`);
JSONValue v2 = parseJSONValue(str);
assert(v2 == 2.0);
assert(str == ``);

See Also

toJSONValue

Meta