Construct a json instance, with a default value of null
use these types for external references
enumerates the seven acceptable JSON value types
Create an array of values
Create an attribute/value pair, where value defaults to null
Parse the given text and return a resultant Value type. Also sets the document value.
Return a text representation of this document
Returns the root value of this document
Set the root value of this document
Create a text value
Create a boolean value
Create a numeric value
Create a single Value from an array of Values
Represents a single json Object (a composite of named attribute/value pairs).
Represents a json value that is one of the seven types specified via the Json.Type enum
Represents an attribute/value pair. Aliased as Attribute
with (new Json!(char)) { root = object ( pair ("edgar", value("friendly")), pair ("count", value(11.5)), pair ("array", value(array(1, 2))) ); auto value = toString(); assert (value == `{"edgar":"friendly","count":11.5,"array":[1, 2]}`, value); }
// check with a separator of the tab character with (new Json!(char)) { root = object ( pair ("edgar", value("friendly")), pair ("count", value(11.5)), pair ("array", value(array(1, 2))) ); auto value = toString ("\t"); assert (value == "{\n\t\"edgar\":\"friendly\",\n\t\"count\":11.5,\n\t\"array\":[\n\t\t1, \n\t\t2\n\t]\n}", value); }
// check with a separator of five spaces with (new Json!(dchar)) { root = object ( pair ("edgar", value("friendly")), pair ("count", value(11.5)), pair ("array", value(array(1, 2))) ); auto value = toString (" "); assert (value == "{\n \"edgar\":\"friendly\",\n \"count\":11.5,\n \"array\":[\n 1, \n 2\n ]\n}"); }
Parse json text into a set of inter-related structures. Typical usage is as follows:
Converting back to text format employs a delegate. This one emits document content to the console:
Constructing json within your code leverages a handful of factories within a document instance. This example creates a document from an array of values:
Setting the document to contain a simple object instead:
Objects may be constructed with multiple attribute pairs like so:
Substitute arrays, or other objects as values where appropriate:
TODO: document how to extract content
Big thanks to dhasenan for suggesting the construction notation. We can't make effective use of operator-overloading, due to the use of struct pointers, so this syntax turned out to be the next best thing.