Jump to content

Json or not to json?


Rhiannon Arkin
 Share

You are about to reply to a thread that has been inactive for 1883 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

json is mebbe a little easier than manipulating a lot of lists and list items?

you can do something like....

 

 string  Stations = llList2Json( JSON_OBJECT, [] ); 

name = "jazz"
 url = "http://some.jazz.stream";
      if (llJsonGetValue (Stations, [name] ) == JSON_INVALID)
     {   Stations = llJsonSetValue (Stations, [name,  "URL"], url);                   
     }

 

and then get the info from the exact location by name,

(if your listen event gets the string message "jazz")

 TuneIn = llJsonGetValue (Stations, [Msg, "URL"]) ;
 llSetParcelMusicURL(TuneIn);    

you can do most of the json stuff with strided lists, so, what ever you like :)

 

http://wiki.secondlife.com/wiki/Json_usage_in_LSL

http://wiki.secondlife.com/wiki/Talk:Json_usage_in_LSL

http://wiki.secondlife.com/wiki/User:Vegas_Silverweb/LSL_to_JSON

 

Edited by Xiija
  • Like 1
Link to comment
Share on other sites

Json allows to store data in a record/array structure. If you need that or want to export data in that format - use json.

I personally didn't have any use for it. Lists are good for my stuff. If I ever have a complicated multi dimensional data structure I will consider to use json for that but for the usual simple stuff I don't need it.

  • Like 1
Link to comment
Share on other sites

On 6/24/2017 at 6:04 AM, Nova Convair said:

Json allows to store data in a record/array structure. If you need that or want to export data in that format - use json.

I personally didn't have any use for it. Lists are good for my stuff. If I ever have a complicated multi dimensional data structure I will consider to use json for that but for the usual simple stuff I don't need it.

Agree, I've been avoiding using JSON all these years, but finally have a project with a complex enough data structure requirement to justify it. 

Link to comment
Share on other sites

  • 1 year later...

Some things bothered me about this thread, I'll clear them up here about json:

1.  Json is not useless, its basically the language nearly every RESTFul  API and data-driven HTTP-standardized and secure HTTPS API talks in on the internet (XML being another language API talks in, but thats another story).  sURLs talk in json when sent a GET request, as an example.  Its how data is relayed to/from second life database servers, and external sources, such as a product developer's website for registration information and personalized owner settings stored in an object.

2.  Json is not time-critical.  It was designed as a web communication protocol to pass data to and from a web-server, and should be used that way.  It is similar in concept to what HTML is, and what XML is.  If you find yourself using json objects without making http/https requests, you probably should be looking at some other way to store your objects.

3.  Json data should be treated with a hard upper limit of 4096 UTF-8 byes in core LSL and 16384 UTF-8 bytes in Mono as part of the request body limit of the LSL web toolkit.  LSL is not designed nor optimized to handle json structures larger than this.  Most API will never send/accept much more than this if properly designed, anyway, with Second Life in mind.

4. Json serialization/deserialization inclusion in LSL is an essential part of the Second Life LSL web toolkit, and makes all of our lives much easier when dealing with CRUD-model based API and database systems on and off second life.  If you've ever dealt with a notecard memory database, you'll be pleased to know you can toss that code out - LSL is Json and RESTFul web HTTP request friendly.

5.  Json should never be used as a permanent method of documentstore (datastore). Its simply a communication protocol designed to send objects to/from a more permanent document store, such as an api which stores/retrieves information from a  mysql database, sqllite implementation, or nosql implementation that can reply to queries efficiently and process data quickly.  It is not optimized for speed, but is for portability.

For more information, please visit these help topics:

What is Json?  (web protocol)

https://www.w3schools.com/whatis/whatis_json.asp

Making HTTP/Secure HTTPS put/get requests with LSL

http://wiki.secondlife.com/wiki/LlHTTPRequest

Serializing/Deserializing request bodies with LSL - Json structure to native LSL objects and back:

http://wiki.secondlife.com/wiki/Json_usage_in_LSL

 

  • Like 2
Link to comment
Share on other sites

On 7/3/2017 at 12:51 PM, Dora Gustafson said:

JSON in LSL is slow compared to a similar task solved the traditional way with lists

Avoid using JSON it in time critical applications

Use JSON for complex list arrays when the execution time is not critical

No, a list and a JSON  are two different beasts. You use one or the other to siut its purpose.

Link to comment
Share on other sites

I see a few interesting possibilities with Json

  • Protocols: Adding extra data/unofficial extensions/phasing out legacy data in a protocol without any risks of parsing failure.
  • Serialization: An object might pass to another object data that it will "need later" (when it is re-rezzed for instance is rezzed for example), and json is a good way to store that data.
  • Data hiearchy: If for some reason you need something that behaves like a filesystem tree.

Time will tell if the memory usage  for storage/runtime turns out to be smaller than manipulating lists. I certainly like not having to deal with list offsets at the very least.

Link to comment
Share on other sites

LSL doesn't support lists-within-lists, so I like the idea of using JSON for that.

What I've actually used it for is a menu-system. I allow users to write their desired menu layout into a notecard (not in pure JSON but something simpler), and then I parse it into JSON. Though, even the pure-JSON format would be pretty simple for menu-layouts. (Some superfluous brackets omitted)

"main menu":
{
    "menu a":
    [
        "button 1",
        "button 2",
        "button 3"
    ],

    "menu b":
    [
        "button 1",
        "button 2",
        "button 3",
        "button 4",
        "button 5",
        {"submenu 1":[
            "button 1",
            "button 2",
            "button 3"
        ]}
    ],

    "menu c":
    [
        "button 1",
        "button 2",
        "button 3",
        "button 4"
    ]
}

Edited by Wulfie Reanimator
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1883 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...