vibe.d beta banner
get vibe.d
0.8.2

Asynchronous I/O that doesn’t get in your way, written in D

Module vibe.data.json

JSON serialization and value handling.

This module provides the Json struct for reading, writing and manipulating JSON values in a seamless, JavaScript like way. De(serialization) of arbitrary D types is also supported.

Examples

void manipulateJson(Json j)
{
	// object members can be accessed using member syntax, just like in JavaScript
	j = Json.emptyObject;
	j.name = "Example";
	j.id = 1;

	// retrieving the values is done using get()
	assert(j["name"].get!string == "Example");
	assert(j["id"].get!int == 1);

	// semantic conversions can be done using to()
	assert(j.id.to!string == "1");

	// prints:
	// name: "Example"
	// id: 1
	foreach( string key, value; j ){
		writefln("%s: %s", key, value);
	}

	// print out as JSON: {"name": "Example", "id": 1}
	writefln("JSON: %s", j.toString());
}

Functions

NameDescription
convertJsonToASCII(json)Helper function that escapes all Unicode characters in a JSON string.
parseJsonString(str, filename)Parses the given JSON string and returns the corresponding Json object.

Structs

NameDescription
JsonRepresents a single JSON value.
JsonSerializerSerializer for a plain Json representation.
JsonStringSerializerSerializer for a range based plain JSON string representation.

Templates

NameDescription
deserializeJsonDeserializes a JSON value into the destination variable.
parseJsonParses the given range as a JSON string and returns the corresponding Json object.
serializeToJsonSerializes the given value to JSON.
serializeToJsonStringSerializes the given value to JSON.
writeJsonStringWrites the given JSON object as a JSON string into the destination range.
writePrettyJsonStringWrites the given JSON object as a prettified JSON string into the destination range.
Authors

Sönke Ludwig

Copyright

© 2012-2013 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.