Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.json

JavaScript Object Notation
License:
Authors:
Jeremie Pelletier, David Herberth

References: http://json.org/

Source: std/json.d

enum JSON_TYPE: byte;
JSON type enumeration
STRING
INTEGER
UINTEGER
FLOAT
OBJECT
ARRAY
TRUE
FALSE
NULL
Indicates the type of a JSONValue.
struct JSONValue;
JSON value node
const @property JSON_TYPE type();
Specifies the type of the value stored in this structure.
deprecated @property JSON_TYPE type(JSON_TYPE newType);
Deprecated. Instead, please assign the value with the adequate type to JSONValue directly. This will be removed in June 2015.
Sets the type of this JSONValue. Previous content is cleared.
inout @property inout(string) str();
@property string str(string v);
Value getter/setter for JSON_TYPE.STRING.
Throws JSONException for read access if type is not JSON_TYPE.STRING.
inout @property inout(long) integer();
@property long integer(long v);
Value getter/setter for JSON_TYPE.INTEGER.
Throws JSONException for read access if type is not JSON_TYPE.INTEGER.
inout @property inout(ulong) uinteger();
@property ulong uinteger(ulong v);
Value getter/setter for JSON_TYPE.UINTEGER.
Throws JSONException for read access if type is not JSON_TYPE.UINTEGER.
inout @property inout(double) floating();
@property double floating(double v);
Value getter/setter for JSON_TYPE.FLOAT.
Throws JSONException for read access if type is not JSON_TYPE.FLOAT.
inout @property ref inout(JSONValue[string]) object();
@property JSONValue[string] object(JSONValue[string] v);
Value getter/setter for JSON_TYPE.OBJECT.
Throws JSONException for read access if type is not JSON_TYPE.OBJECT.
inout @property ref inout(JSONValue[]) array();
@property JSONValue[] array(JSONValue[] v);
Value getter/setter for JSON_TYPE.ARRAY.
Throws JSONException for read access if type is not JSON_TYPE.ARRAY.
this(T)(T arg) if (!isStaticArray!T);
this(T)(ref T arg) if (isStaticArray!T);
inout this(T : JSONValue)(inout T arg);
Constructor for JSONValue. If arg is a JSONValue its value and type will be copied to the new JSONValue. Note that this is a shallow copy: if type is JSON_TYPE.OBJECT or JSON_TYPE.ARRAY then only the reference to the data will be copied. Otherwise, arg must be implicitly convertible to one of the following types: typeof(null), string, ulong, long, double, an associative array V[K] for any V and K i.e. a JSON object, any array or bool. The type will be set accordingly.
inout ref inout(JSONValue) opIndex(size_t i);
Array syntax for json arrays.
Throws JSONException if type is not JSON_TYPE.ARRAY.
inout ref inout(JSONValue) opIndex(string k);
Hash syntax for json objects.
Throws JSONException if type is not JSON_TYPE.OBJECT.
int opApply(int delegate(size_t index, ref JSONValue) dg);
Implements the foreach opApply interface for json arrays.
int opApply(int delegate(string key, ref JSONValue) dg);
Implements the foreach opApply interface for json objects.
const string toString();
Implicitly calls toJSON on this JSONValue.
const string toPrettyString();
Implicitly calls toJSON on this JSONValue, like toString, but
also passes true as pretty argument.
JSONValue parseJSON(T)(T json, int maxDepth = -1) if (isInputRange!T);
Parses a serialized string and returns a tree of JSON values.
string toJSON(in JSONValue* root, in bool pretty = false);
Takes a tree of JSON values and returns the serialized string.
If pretty is false no whitespaces are generated. If pretty is true serialized string is formatted to be human-readable. No exact formatting layout is guaranteed in the latter case.
class JSONException: object.Exception;
Exception thrown on JSON errors