JsonParse

JsonParse(string, [integerAsFloat]): JsonObject

Parse input string to JsonObject

Table 1. Parameters

string

JSON as a string.

integerAsFloat

Optional boolean parameter. If set to true, all integers in JSON will be interpreted as floating point numbers. Default is false. Available starting from version 5.2.4.

Return

JsonObject if root object is Json object and JsonArray if root object is Json array or null if failed to parse

Global Variables Set on Error

When JSON parsing fails, the following global variables are set:

$jsonErrorMessage

Error message describing the parsing failure.

$jsonErrorLine

Line number where the parsing error occurred.

$jsonErrorColumn

Column number where the parsing error occurred.

Basic usage
// Parse a simple JSON object
json = JsonParse('{"name": "John", "age": 30}');
if (json) {
    println("Name: " .. json->name);
    println("Age: " .. json->age);
}
Using integerAsFloat parameter
// Parse JSON with integers as floating point
json = JsonParse('{"value": 42}', true);
if (json) {
    println("Value type: " .. typeof(json->value)); // Will be "real"
}

// Parse JSON with integers as integers (default behavior)
json = JsonParse('{"value": 42}', false);
if (json) {
    println("Value type: " .. typeof(json->value)); // Will be "int64"
}
Error handling using global variables
// Attempt to parse invalid JSON
json = JsonParse('{"name": "John", "age":}'); // Missing value after colon
if (!json) {
    println("JSON parsing failed:");
    println("  Error: " .. $jsonErrorMessage);
    println("  Line: " .. $jsonErrorLine);
    println("  Column: " .. $jsonErrorColumn);
}