toNBT

Converts a JSONValue into a Tag.

toNBT
(
JSONValue json
)

Return Value

Type: Tag

an instance of Compound when the json is an object, and instance of List when the json is an array, an instance of String when the json is a string, an instance of Long when the json is an integer, an instance of Double when the json is a floating point number, an instance of Byte (with values 0 and 1) when the json is a boolean and null when the json is null.

Examples

t {

	assert(toNBT(JSONValue(true)) == new Byte(1));
	assert(toNBT(JSONValue([1, 2, 3])) == new ListOf!Long(1, 2, 3));
	assert(toNBT(JSONValue(["a": [42]])) == new Compound(new Named!(ListOf!Long)("a", 42)));
	//assert(toNBT(JSONValue(["a": [42]])) == new Compound(new Named!List("a", new Long(42)))); //FIXME
	assert(toNBT(JSONValue("test")) == new String("test"));
	assert(toNBT(JSONValue(42)) == new Long(42));
	assert(toNBT(JSONValue(42u)) == new Long(42));
	assert(toNBT(JSONValue(.523)) == new Double(.523));
	assert(toNBT(JSONValue(true)) == new Byte(1));
	assert(toNBT(JSONValue(false)) == new Byte(0));
	assert(toNBT(JSONValue(null)) is null)

Meta