This function takes a list and returns a JSON string of that list as either a json object or json array.
string llList2Json( string type, list values );
Forced delay: 0.0 seconds.
To convert a json formatted string into a list use llJson2List.
Returns a string that is either values serialized as a JSON type, or if an error was encountered JSON_INVALID.
| Type Flags | Value | Unicode | Integer | URL Encoded | HTML Encoded | Description |
|---|---|---|---|---|---|---|
| JSON_INVALID | | U+FDDO | 64976 | "%EF%B7%90" |  | Value returned when inputs are not well formed. |
| JSON_OBJECT | | U+FDD1 | 64977 | "%EF%B7%91" |  | |
| JSON_ARRAY | | U+FDD2 | 64978 | "%EF%B7%92" |  |
llJson2List(llList2Json(JSON_ARRAY, ["bacon", "true", "false", "null"])) returns the LSL list ["bacon", JSON_TRUE, JSON_FALSE, JSON_NULL], while llJson2List(llList2Json(JSON_ARRAY, ["\"bacon\"", "\"true\"", "\"false\"", "\"null\""])) returns the LSL list ["bacon", "true", "false", "null"]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.
Date of Release 20/05/2013