Difference between revisions of "LlJson2List"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL Function |func_id=|func_sleep=0.0|func_energy=10.0 |func=llJson2List|return_type=list|p1_type=string|p1_name=src |func_footnote= To convert a list into a json formatted str…")
 
m (<lsl> tag to <source>)
 
(5 intermediate revisions by 4 users not shown)
Line 12: Line 12:
|constants
|constants
|examples=
|examples=
<source lang="lsl2">
string Json2CSV(string jcsv){//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(jcsv);
    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.
</source>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llList2Json]]|}}
|also_functions={{LSL DefineRow||[[llList2Json]]|}}
Line 23: Line 34:
|permission
|permission
|negative_index
|negative_index
|sort=CSV2List
|sort=Json2List
|cat1=List
|cat1=List
|cat2=String
|cat2=String
|cat3=Data Conversion
|cat3=Data Conversion
|cat4=Json
|cat4=JSON
|history = Date of Release  [[ Release_Notes/Second_Life_Server/13#13.05.20.276191 | 20/05/2013 ]]
}}
}}

Latest revision as of 11:33, 22 January 2015

Summary

Function: list llJson2List( string src );

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

See Json_usage_in_LSL

  • 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

string Json2CSV(string jcsv){//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(jcsv);
    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.

See Also

Functions

•  llList2Json
•  llJsonGetValue
•  llJsonSetValue
•  llJsonValueType

Articles

•  Typecast

Deep Notes

History

Date of Release 20/05/2013

Search JIRA for related Issues

Signature

function list llJson2List( string src );