std.json

Module entries: JSONValue, __jv()

class JSONValue

This type represents a JSON value.

Example:

auto value = JSONValue([("Hello", JSONValue("World"))]);
assert(value.toString == "{\"Hello\": \"World\"}");
assert(JSONValue.parse("{\"Hello\": \"World\"}").toString == "{\"Hello\": \"World\"}");
parse(str)

JSONValue parse(string str)

Parse a JSON value from a string.

loadFile(file)

JSONValue loadFile(string file)

Load a JSON value from a file.

integer()

int integer()

Interprets a JSON value as an integer.

str()

string str()

Interprets a JSON value as a string.

boolean()

bool boolean()

Interprets a JSON value as a boolean.

array()

JSONValue[] array()

Interprets a JSON value as an array.

object()

(string key, JSONValue value)[] object()

Interprets a JSON value as an object.

isArray()

bool isArray()

Returns true if the JSON value is an array.

isObject()

bool isObject()

Returns true if the JSON value is an object.

get(key)

JSONValue get(string key)

Returns the JSON value for a key.

has(key)

bool has(string key)

Returns true if the JSON value, which must be an object, contains the key.

set(key, value)

void set(string key, JSONValue value)

Sets the given key to a value.

keys()

string[] keys()

Given the value is an object, returns an array of string keys.

toString()

string toString()

Converts a JSON value to a string.

__jv(arg)

JSONValue __jv((bool | int | JSONValue[] | string | (string key, JSONValue value)[] | JSONValue) arg)

TODO: document