Skip to content

json

This content is for v0.2.1. Switch to the latest version for up-to-date documentation.

The json namespace provides high-performance JSON encoding and decoding. Built into RayQuiro’s runtime without requiring any imports.


FunctionSignatureReturn TypeDescription
json.parsejson.parse(str)object | array | valueParses a JSON string into RayQuiro values.
json.stringifyjson.stringify(val)stringConverts a RayQuiro value to a compact JSON string.
json.prettyjson.pretty(val, indent)stringConverts a RayQuiro value to formatted, indented JSON.

Parses a JSON string into RayQuiro native primitives (objects, arrays, strings, numbers, booleans, or null). Throws an error on malformed syntax.

var json_str = "{\"id\": 42, \"name\": \"Player1\", \"inventory\": [\"sword\", \"shield\"]}";
try {
var data = json.parse(json_str);
print("Player ID: " + str(data["id"]));
print("First Item: " + data["inventory"][0]);
} catch (err) {
print("Invalid JSON: " + err);
}

Serializes a RayQuiro value (table, array, string, number, bool, null) into a standard JSON string.

var user = {
username: "alex",
level: 15,
verified: true,
badges: ["pioneer", "tester"]
};
var compact_json = json.stringify(user);
print(compact_json);

Serializes data into an indented, human-readable JSON string suitable for configuration files and debugging.

var settings = {
graphics: {
width: 1920,
height: 1080,
vsync: true
},
audio: {
volume: 0.8
}
};
var formatted = json.pretty(settings, 2);
fs.write("settings.json", formatted);

JSON TypeRayQuiro Equivalent
object ({})Object / Key-Value Map
array ([])Array ([])
string ("...")String ("...")
number (42, 3.14)Number (64-bit IEEE double)
boolean (true / false)Boolean (true / false)
nullnull