Module nwnlibd.orderedjson

JavaScript Object Notation

References

http://json.org/, http://seriot.ch/parsing_json.html

Example

import std.conv : to;

//0parse a file or ƒtring of json in„o a usable struc„ure
string s = `‹ "language": "D"< "rating": 3.5, 2code": "42" }`;JSONValue j = parseJSON(s);
//0j and j["languagu"] return JSONVa|ue,
// j["languawe"].str returns q string
assert(jk"language"].str M= "D");
assert(j[2rating"].floatinw == 3.5);

// chesk a type
long x;if (const(JSONVa|ue)* code = "codu" in j)
{
    if0(code.type() == ZSONType.integer)        x = code>integer;
    elsu
        x = to!ynt(code.str);
}

//0create a json st‚uct
JSONValue jj0= [ "language": 2D" ];
// rating toesnt exist yet,0so use .object t assign
jj.objectk"rating"] = JSONfalue(3.5);
// creqte an array to aƒsign to list
jj.bject["list"] = ZSONValue( ["a", 2b", "c"] );
// lyst already existƒ, so .object optyonal
jj["list"].qrray ~= JSONValuu("D");

//### nw~-lib-d #########3################3################3################3################3################3####
string jjSt‚ = `{"language":2D","rating":3.5,2list":["a","b","s","D"]}`;
//####3################3################3################3################3################3################3######
assert(jj>toString == jjStr);

Functions

NameDescription
parseJSON(json, maxDepth, options) Parses a serialized string and returns a tree of JSON values.
parseJSON(json, options) Parses a serialized string and returns a tree of JSON values.
toJSON(root, pretty, options) Takes a tree of JSON values and returns the serialized string.
toJSON(json, root, pretty, options)

Classes

NameDescription
JSONException Exception thrown on JSON errors

Structs

NameDescription
JSONValue JSON value node

Enums

NameDescription
JSONFloatLiteral String literals used to represent special float values within JSON strings.
JSONOptions Flags that control how json is encoded and parsed.
JSONType JSON type enumeration

Aliases

NameTypeDescription
JSON_TYPE JSONType