Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

[BUG-6280] llList2Json converts strings "true", "false", "null" into JSON constants #14154

Closed
sl-service-account opened this issue Jun 6, 2014 · 4 comments

Comments

@sl-service-account
Copy link

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
Field Value
Issue BUG-6280
Summary llList2Json converts strings "true", "false", "null" into JSON constants
Type Bug
Priority Unset
Status Closed
Resolution Expected Behavior
Reporter Ray Silent (ray.silent)
Created at 2014-06-06T19:46:55Z
Updated at 2014-06-07T01:06:58Z
{
  'Business Unit': ['Platform'],
  'Date of First Response': '2014-06-06T15:01:11.059-0500',
  'System': 'SL Simulator',
  'Target Viewer Version': 'viewer-development',
  'What just happened?': 'There are several input strings producing the same JSON values true, false, null',
  'What were you doing when it happened?': 'default\r\n{\r\n    state_entry()\r\n    {\r\n        string json=llList2Json(JSON_ARRAY, ["one", "true", JSON_TRUE, "false", JSON_FALSE, "null", JSON_NULL, "True","False","Null"]);\r\n        llSay(0, json);\r\n        llSay(0, llList2CSV(llJson2List(json)));\r\n    }\r\n}\r\n\r\n\r\nproduces this output:\r\n\r\n["one",true,true,false,false,null,null,"True","False","Null"]\r\n\r\none, \ufdd6, \ufdd6, \ufdd7, \ufdd7, \ufdd5, \ufdd5, True, False, Null\r\n\r\ninstead of original string\r\n\r\n["one", "true", JSON_TRUE, "false", JSON_FALSE, "null", JSON_NULL, "True","False","Null"]',
  'What were you expecting to happen instead?': '["one", "true", JSON_TRUE, "false", JSON_FALSE, "null", JSON_NULL, "True","False","Null"]',
}
@sl-service-account
Copy link
Author

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?

@sl-service-account
Copy link
Author

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.

@sl-service-account
Copy link
Author

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)));
    }

}

@sl-service-account
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant