This function takes a list and returns a JSON string of that list as either a json object or json array.

Syntax

string llList2Json( string type, list values );

Forced delay: 0.0 seconds.

Parameters

string type
list values

To convert a json formatted string into a list use llJson2List.

Return value

Returns a string that is either values serialized as a JSON type, or if an error was encountered JSON_INVALID.

Specification

See Json_usage_in_LSL

Constants

Type FlagsValueUnicodeIntegerURL EncodedHTML EncodedDescription
JSON_INVALID﷐U+FDDO64976"%EF%B7%90"Value returned when inputs are not well formed.
JSON_OBJECT﷑U+FDD164977"%EF%B7%91"
JSON_ARRAY﷒U+FDD264978"%EF%B7%92"

Caveats

Examples

default
{
    state_entry()
    {
        list items;
        string json;

        items = ["89556747-24cb-43ed-920b-47caed15465f"];
        json = llList2Json(JSON_ARRAY, items);
        // ["89556747-24cb-43ed-920b-47caed15465f"]

        items = ["pi", 3.14, "set", "[1,2,3]", "status", "ok"];
        json = llList2Json(JSON_OBJECT, items);
        // {"pi":3.140000,"set":[1,2,3],"status":"ok"}

        items = [0, 3.14, "[1,2,3]", "{}"];
        json = llList2Json(JSON_ARRAY, items);
        // [0,3.140000,[1,2,3],{}]
    }
}
string CSV2Json(string csv)
{
    list li = llCSV2List(csv);
    return llList2Json(JSON_ARRAY, li);
}
// This function converts a comma separated values string to a Json array string. 
// CSV strings are often used for link-messages, notecards and they are easier to type as input commands. 
// A Json-Array can store multiple of those as a nested list within the same Json-string via JSON_APPEND.

See also

Constants

Functions

Articles

Deep notes

History

Date of Release 20/05/2013