Difference between revisions of "LlJson2List"
(+1 barely useful example, except to compress json string size a little bit) |
(#example that makes sense, under some conditions) |
||
Line 13: | Line 13: | ||
|examples= | |examples= | ||
<lsl> | <lsl> | ||
string Json2CSV(string csv){ | string Json2CSV(string csv){//Converts a Json into a string of comma separated values. == Removes the top level [ and ] and all " from top level JSON_STRING values. | ||
list li llJson2List(li); | list li llJson2List(li); | ||
return llList2CSV(Li); | return llList2CSV(Li); | ||
}// | } | ||
//If the | //If the Json is a 1-dimensional array of strings like "[\"a\",\"b\",\"c\"]", the returned CSV-string will be: "a,b,c" //This is a much shorter CSV that will save some memory. | ||
//If the Json contains a nested arrays like "[[1,2],["PI",4]]", the returned csv string will be : "[1,2],[\"Pi\",4]" | |||
//"[1,2],[\"Pi\",4]" is not a very readable CSV-string and not shortened by much. "PI" is not a top level string value because it is nested 1 level deeper.llJson2List unescapes those. | |||
</lsl> | </lsl> | ||
Revision as of 03:41, 15 September 2014
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: list llJson2List( string src );0.0 | Forced Delay |
10.0 | Energy |
This function takes a string representing JSON, and returns a list of the top level.
Returns a list made by parsing src, a string representing json.
• string | src |
To convert a list into a json formatted string use llList2Json.
Specification
- If the json represents a single item (number, string, true, false or null) then a list with 1 item will be returned.
- If the json represents an object then a strided list of key, value pairs is returned. All values that are objects or arrays are returned as json strings.
- If the json represents an array then a list of all items is returned. All values that are objects or arrays are returned as json strings.
Examples
<lsl> string Json2CSV(string csv){//Converts a Json into a string of comma separated values. == Removes the top level [ and ] and all " from top level JSON_STRING values.
list li llJson2List(li); return llList2CSV(Li);
} //If the Json is a 1-dimensional array of strings like "[\"a\",\"b\",\"c\"]", the returned CSV-string will be: "a,b,c" //This is a much shorter CSV that will save some memory. //If the Json contains a nested arrays like "[[1,2],["PI",4]]", the returned csv string will be : "[1,2],[\"Pi\",4]" //"[1,2],[\"Pi\",4]" is not a very readable CSV-string and not shortened by much. "PI" is not a top level string value because it is nested 1 level deeper.llJson2List unescapes those.
</lsl>