Json

This is a forward JSON parser for picking off items of interest on the go. It neither produces a node structure, nor does it produce events. Instead you can peek at the value type that lies ahead and/or directly consume a JSON value from the parser. Objects and arrays can be iterated over via foreach, while you can also directly ask for one or multiple keys of an object.

Prams: vl = Validation level. Any of trustedSource, validateUsed or validateAll. validateUtf8 = If validation is enabled, this also checks UTF-8 encoding of JSON strings.

Constructors

this
this()
Undocumented in source.
this
this(string text, Flag!"simdPrep" simdPrep)

Constructor taking a string for fast slicing.

this
this(const(char)[] text, Flag!"simdPrep" simdPrep)

Constructor taking a const char[].

Postblit

this(this)
this(this)
Undocumented in source.

Members

Aliases

opDispatch
alias opDispatch = singleKey

An alias to the singleKey method. Instead of json.singleKey!"something" you can write json.something. Read the notes on singleKey.

Functions

borrowString
const(char)[] borrowString()

Reads a string off the JSON text with limited lifetime.

keySwitch
void keySwitch(void delegate()[Args.length] dlg)

Selects from a set of given keys in an object and calls the corresponding delegate. The difference to singleKey when invoked with a single key is that keySwitch will not error out if the key is non-existent and may trigger the delegate multiple times, if the JSON object has duplicate keys.

opApply
int opApply(int delegate(const size_t) foreachBody)

Iterate over a JSON array via foreach.

read
string read(bool allowNull)

Reads a string off the JSON text.

read
T read()

Reads an enumeration off the JSON text.

read
N read()

Reads a number off the JSON text.

read
T read()

Reads a plain old data struct off the JSON text.

read
T read()

Reads a plain old data struct or null off the JSON text.

read
T read()

Reads an associative-array off a JSON text.

read
T read()

Reads a dynamic array off the JSON text.

read
T read()

Reads a static array off the JSON text.

read
bool read()

Reads a boolean value off the JSON text.

readNull
typeof(null) readNull()

Reads null off the JSON text.

skipValue
void skipValue()

Skips the next JSON value if you are not interested.

Properties

byKey
int delegate(scope int delegate(ref const char[])) byKey [@property getter]

Iterate the keys of a JSON object with foreach.

peek
DataType peek [@property getter]

Returns the type of data that is up next in the JSON text.

singleKey
SingleKey singleKey [@property getter]

Skips all keys of an object except the first occurence with the given key name.

state
const(JsonParserState) state [@property getter]

Save or restore the parser's internal state.

state
JsonParserState state [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.

Meta