[BUG-6284] Inconsistent handling of numbers in llList2Json #14157
Comments
Maestro Linden commented at 2014-06-07T00:36:20Z Hi Sei, can you please elaborate on the behavior you expect for those two output lines? Is it that llJsonSetValue("",[0],"1") should return the same output as llList2Json(JSON_ARRAY, ["1"]) (i.e. that llJsonSetValue() should not have type inference for numbers), or something else? The sentence preceding the one that you quote hints at a key difference between how llList2Json and llJsonSetValue interpret input - llList2Json() takes LSL datatypes in the input 'values' list (which may be LSL strings, integers, etc.), whereas llJsonSetValue() takes json strings as input for 'value'. |
Sei Lisa commented at 2014-06-07T00:48:22Z Yes, I expect llList2Json(JSON_ARRAY, ["1"]) to return [1], not ["1"], given that per the documentation, strings are parsed when not quoted, and parsing a JSON number results in a JSON number (just like parsing 'null' results in 'null'). Otherwise it's inconsistent with the behavior with respect to e.g. llList2Json(JSON_ARRAY, ["false"]) which results in [false], and also with the behavior of llJsonSetValue. |
Sei Lisa commented at 2014-06-07T00:56:18Z Another example: llJsonSetValue("[]", [0], "2e3") produces [2e3], but llJsonSetValue("[]", [0], "2e3a") produces ["2e3a"]. Yet llList2Json(JSON_ARRAY, ["2e3", "2e3a"]) produces ["2e3", "2e3a"]. My point is that the fact that LSL types exist that correspond to the JSON number type should not alter the behavior when passing an unquoted string. |
Maestro Linden commented at 2014-06-09T18:32:28Z, updated at 2014-06-09T18:32:58Z No, type inference is expected for llList2Json(). This script illustrates the behavior for various types:
The output is:
I've added a point in the wiki to make this behavior prominent in the specification: |
Steps to Reproduce
Create the following script:
Actual Behavior
The output is:
Note the last "1" with quotes.
Expected Behavior
In the documentation http://wiki.secondlife.com/wiki/Json_usage_in_LSL in the bullet point String, the last sentence reads:
"LSL strings which both begin and end with """ are interpreted literally as JSON strings, while those without are parsed when converted into JSON."
Therefore it's expected for the result to be the same in both cases, namely without quotes around the number that gets passed as a string.
Original Jira Fields
The text was updated successfully, but these errors were encountered: