Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006540opensim[REGION] OpenSim Corepublic2013-02-11 16:022014-07-29 13:42
Assigned Tocmickeyb 
PlatformOSOS Version
Product Versionmaster (dev code) 
Target Versionmaster (dev code)Fixed in Version 
Summary0006540: JsonGetValue() and JsonGetValueJson() differ slightly in return value when they return leaf nodes
DescriptionJsonGetValue() and JsonGetValueJson() JSON script functions return slightly different values for leaf-nodes. In the script below, JsonGetValue() returns one, whilst JsonGetValueJson() returns 'one'.

This could be confusing if user is using the value in a comparison and substitutes JsonGetValue() for JsonGetValueJson() for some reason (maybe because they also want to compare larger structures, though that would be a fairly horrific thing to do). What do you think? Should we strip the single quotes when JsonGetValueJson() is return a leaf node (single quotes are also inconsistent with the double quotes used in a subtree!)
Steps To Reproducekey storeID;
    touch_start(integer n)
        storeID = JsonCreateStore("{ 'foo' : { 'bar' : 'one' } }");
        llOwnerSay(JsonGetValue(storeID, "")); // Says one
        llOwnerSay(JsonGetValueJson(storeID, "")); Says 'one'
TagsNo tags attached.
Git Revision or version number
Run ModeStandalone (1 Region)
Physics EngineODE
Script Engine
EnvironmentMono / Linux64
Mono Version2.10
Attached Files

- Relationships

-  Notes
cmickeyb (administrator)
2013-02-11 16:09

This is by design, but I'm open to changing it.

There is a difference for Json parsing between the bareword string "one" and the token "'one'". These operations should both work (assuming "foo.b" has a leaf value):

JsonSetValue(kStoreID, "foo.a", JsonGetValue(kStoreID,"foo.b"))
JsonSetValueJson(kStoreID, "foo.a", JsonGetValueJson(kStoreID,"foo.b"))

But this should fail (with the json value being unparseable):
JsonSetValueJson(kStoreID, "foo.a", JsonGetValue(kStoreID,"foo.b"))

and this should store "'one'"
justincc (administrator)
2013-02-11 16:37

I would find it rather annoying if I got the value to store from someplace other than JsonGetValueJson() and I knew it was either a sub-tree or a leaf-node but not which. In the latter case I would have to manually find that out and either add more code to call JsonSetValue() or surround the leaf node with '. Admittedly, I can't currently identify a likely situation where this would happen.

On the other hand, I suppose one could use JsonSetValueJson() as a shortcut way to test whether an input was valid json (it sounds like that is your intent). Currently, if it's a string instead then that won't succeed. The string could still be single quoted anyway, but this is less likely in the possibly common case where I've fetched something from a remote server that is a string rather than JSON.

So on balance, perhaps it should be left as it is. I might ask a few scripters what they think sometime soon.
cmickeyb (administrator)
2013-02-11 16:43

Not sure what you mean... "one" is not a valid json value. The parser will fail. "'one'" is valid. The distinction in operations is to make explicit that you are working with Json NOT working with raw values. If you call the GetValueJson() operation then you should get something that is a valid chunk of Json.
justincc (administrator)
2013-02-11 16:45

Sorry, meant string, not leaf-node above
cmickeyb (administrator)
2013-02-11 16:54

So i'm still not sure what you're suggesting. If a string is Json you should use the Json operations. If a string is a string, then use the straight value operations. I'm not sure it needs to be any more difficult than that.

I would expect the result of JsonGetValueJson() to be Json regardless of whether its a leaf or intermediate node. Thats how it works now.
cmickeyb (administrator)
2013-02-11 17:24

Per IRC conversation...

For base values, strip the quotes on a Set when the string fails to parse. If there are no quotes, then the operation fails.
cmickeyb (administrator)
2013-02-11 20:01

The fix to strip quotes seems to address the problem. Though there are some oddities with empty strings. The OSD Json serializer seems to think that these are default values and does not serialize them.

- Issue History
Date Modified Username Field Change
2013-02-11 16:02 justincc New Issue
2013-02-11 16:02 justincc Status new => assigned
2013-02-11 16:02 justincc Assigned To => cmickeyb
2013-02-11 16:05 justincc Summary JsonGetValue() and JsonGetValueJson() return slightly when they return leaf nodes => JsonGetValue() and JsonGetValueJson() differ slightly in return value when they return leaf nodes
2013-02-11 16:09 cmickeyb Note Added: 0023567
2013-02-11 16:37 justincc Note Added: 0023568
2013-02-11 16:43 cmickeyb Note Added: 0023569
2013-02-11 16:45 justincc Note Added: 0023570
2013-02-11 16:54 cmickeyb Note Added: 0023571
2013-02-11 17:24 cmickeyb Note Added: 0023572
2013-02-11 20:01 cmickeyb Note Added: 0023573
2013-02-11 20:02 cmickeyb Status assigned => resolved
2013-02-11 20:02 cmickeyb Resolution open => fixed
2014-07-29 13:42 chi11ken Status resolved => closed

Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker