Skip to content

Instantly share code, notes, and snippets.

@gistya
Created June 22, 2013 06:11
Show Gist options
  • Select an option

  • Save gistya/5836069 to your computer and use it in GitHub Desktop.

Select an option

Save gistya/5836069 to your computer and use it in GitHub Desktop.
Some util functions to help with LSL scripting using JSON
//JSON_TYPE integers
integer invalid = 1; //invalid
integer object = 2; //object
integer array = 4; //array
integer number = 8; //number
integer str = 16; //string
integer null = 32; //null
integer true = 64; //true
integer false = 128; //false
//map the json type to a useful bitmask lol
integer jsonType(string json, list specifiers) {
return llRound(llPow(2.,(float)((integer)llGetSubString(
llEscapeURL(llJsonValueType(json,specifiers)),8,8))));
}
//as long as it ain't null or invalid, returns true |=}
integer jsonValid(string value, list spec) {
return (
!( jsonType(value,spec) & (invalid | null) )
);
}
string jsonGetValue(string json, list spec) {
if(jsonValid(json,spec)) return llJsonGetValue(json,spec);
else return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment