Skip to content

json

This content is for v1.0. 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 JSON string.

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);