-
Notifications
You must be signed in to change notification settings - Fork 0
[BUG-6280] llList2Json converts strings "true", "false", "null" into JSON constants #14154
Comments
Sei Lisa commented at 2014-06-06T20:01:11Z, updated at 2014-06-07T01:06:59Z I can reproduce this. It's either a misbehavior or a documentation problem. The Type Conversion section of http://wiki.secondlife.com/wiki/Json_usage_in_LSL does not mention anything regarding conversion of special strings, and the special values JSON_TRUE, JSON_FALSE, JSON_NULL are there for a reason. The very last paragraph in that page states: "NOTE the use of the JSON_TRUE constant in the above to obtain the bare word 'true' for the value of ["gamma", "b"]. If one had used the LSL constant TRUE, they would've incorrectly obtained an integer '1'. The same applies for 'false' and 'null', do not encode them as strings or use the LSL values, use the correct JSON_* type constants." The "do not encode them as strings" part suggests that this behavior is not the expected one. Edit: I believe it was a problem in the documentation. I've edited it accordingly: http://wiki.secondlife.com/w/index.php?title=Json_usage_in_LSL&diff=1191136&oldid=1188019 - can someone please review it for accuracy? |
ObviousAltIsObvious commented at 2014-06-06T20:25:21Z, updated at 2014-06-06T20:31:58Z I see that http://wiki.secondlife.com/wiki/JSON_NULL, http://wiki.secondlife.com/wiki/JSON_FALSE and http://wiki.secondlife.com/wiki/JSON_TRUE include a note: "Also used to set the bare word 'false' as a Value within a Json text using llJsonSetValue and llList2Json." Maybe this behavior is what that is supposed to mean. Bare words are kind of an alien concept to LSL, I'm guessing they meant string. |
ObviousAltIsObvious commented at 2014-06-06T20:41:42Z, updated at 2014-06-06T20:42:04Z All right, it is a documentation problem. When the wiki mentions "bare words", what that means is for the special strings true, false and null, you have to include the quotation marks inside the string to retain the string values. default
{
state_entry()
{
// gets magic conversion
string json=llList2Json(JSON_ARRAY,
["one", "true", "false", "null", "True","False","Null"]);
llSay(0, json);
llSay(0, llList2CSV(llJson2List(json)));
// retains string values
json=llList2Json(JSON_ARRAY,
["one", "\"true\"", "\"false\"", "\"null\"", "True","False","Null"]);
llSay(0, json);
llSay(0, llList2CSV(llJson2List(json)));
}
} |
Maestro Linden commented at 2014-06-06T21:30:45Z This is expected behavior - in the example, the initial strings are not json strings. They should be surrounded by quotation marks to be treated as json strings, as in line 14 from the script in ObviousAltIsObvious' comment. |
Steps to Reproduce
default
{
state_entry()
{
string json=llList2Json(JSON_ARRAY, ["one", "true", "false", "null", "True","False","Null"]);
llSay(0, json);
llSay(0, llList2CSV(llJson2List(json)));
}
}
produces this output:
["one",true,false,null,"True","False","Null"]
one, �, �, �, True, False, Null
instead of original input list
["one", "true", "false", "null", "True","False","Null"]
Actual Behavior
There are several input strings producing the same JSON values true, false, null
Expected Behavior
["one", "true", "false", "null", "True","False","Null"]
Other information
Original Jira Fields
The text was updated successfully, but these errors were encountered: