User Tag List

Results 1 to 6 of 6

Thread: JSON object idea

  1. #1
    Firecodemonkey

    Join Date
    Aug 2006
    Location
    London, UK
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JSON object idea

    (or as I called it in Gwerdy, JSON Darby object)

    JSON, or JavaScript Object Notation, is like XML, but it's a simpler way to store data. How simple? Here's an example of a JSON object:

    {
      "FirstName" : "Chris",
      "Surname" : "Branch",
      "Age" : 19
    }

    The curly braces define a complete object. Then we have three fields, FirstName, Surname and Age with my details. Types are detected automatically, as you only have a few: string, number (integer or floating-point, whatever is more appropriate), true/false, array, object and null (no value). We've seen string, number, and the whole thing up there is an object which could be put inside another object.

    [
      "MagicDeque",
      "Mersenne Twister",
      "Progress Bar"
    ]

    This is an array of my extensions in JSON. It's just an array of strings, noting special, so let's put it in with the rest of my details...

    {
      "FirstName" : "Chris",
      "Surname" : "Branch",
      "Age" : 19,
      "Extensions" :
      [
        "MagicDeque",
        "Mersenne Twister",
        "Progress Bar"
      ]
    }

    Now we have an object with my details and an array of the extensions I've made. No fussy XML trees to worry about - it's all there in fairly simple notation. In JavaScript you would refer to the above object like this:

    myobj.FirstName (this is "Chris")
    myobj.Age (this is 19)
    myobj.Extensions[1] (this is "Mersenne Twister")

    and there is no reason why an extension couldn't let you do the same, as well as common things like iterating through the elements in an array.

    Do we need another data handling object?

    Well... I tend to think so. Simple types are catered for - array, AssArray/Named Variable Object, my own MagicDeque, and of course INI files - but sometimes people are looking for more powerful data structures that let them have arrays of objects within other objects, and other mad, complex things, without keeping track of prefixes and suffixes on Named Variable Objects etc. and having messy, hard-to-track expressions.

    The other benefit of this, which can be applied to existing objects too, is that it's a simple data format for serialisation. You can put an entire object into a string, save it to disk or send it across the internet, whatever you feel like doing is up to you. It's very lightweight and simpler for humans to read. JSON is supported by all the major languages, Google and Yahoo provide web services in this format alongside XML, among others, and for many purposes it's simply an easier format to work with. Even if there isn't a separate object to handle all this in an intuitive, logical manner, support could be added to other objects as a human-readable robust alternative.


    What do you think?

  2. #2
    Clickteam Clickteam
    Jeff's Avatar
    Join Date
    Jun 2006
    Location
    Battle Ground Washington
    Posts
    11,824
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)

    Re: JSON object idea

    Interesting - Never heard of this before but it looks very straight forward.

    If Google and Yahoo have this -- I want it also!
    Got to stay cutting edge before someone asks about it

  3. #3
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: JSON object idea

    Nice idea! Perhaps I could look into it after rSDK, rSDK documentation viewer, rSDK documentation, OINC Server, OINC Client, OINC Socket, String utility, Memory and Console pipe

  4. #4
    Clicker Multimedia Fusion 2 Developer
    Jax's Avatar
    Join Date
    Jul 2006
    Location
    UK
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: JSON object idea

    I think structured data like this is great, but isn't it quite hard to use this sort of thing within mmf? Isn't this more geared towards traditional programming?

  5. #5
    Firecodemonkey

    Join Date
    Aug 2006
    Location
    London, UK
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: JSON object idea

    I think it would be quite easy, actually, if you use the JavaScript syntax to access the data and a few other actions/conditions to handle common constructs. Like JavaScript, if you specify a variable that doesn't exist yet, it will be defined. It's designed to need as little boilerplate code as possible, so to speak. Just set the variable and go.

    myobj.FirstName = "Chris"
    myobj.Surname = "Branch"
    myobj.Age = 19
    myobj.Extensions[0] = "MagicDeque"
    myobj.Extensions[1] = "Mersenne Twister"
    myobj.Extensions[2] = "Progress Bar"

    Why not do exactly this with actions analogous to each line above? We can. It seems the simplest way to do it to me.

    This gives us these basic three ACEs:

    Action: Set (name of variable) to string/value/boolean etc...
    Expression: Get (name of variable) as string/value/boolean
    Condition: Compare to (name of variable)

    And to put the complete object into something useful,

    Action: Deserialise JSON object (string)
    Action: Set (name of variable) to JSON object (string)
    Expression: Serialise JSON object
    Expression: Serialise JSON object at (name of variable)

    It could also import and export XML, but that's outside the scope right now.

    The last major action I can think of is to handle for-each loops. Just like fastloops, but with data in the object; you provide the name of the variable and a loop name, and use a matching 'For Loop' condition. It works for arrays and objects, providing you with the index or key, and perhaps some actions to get/set the variable at that index, as you could have an array of complex objects; the sky's the limit, almost.

    It's a flexible object but it doesn't mean it has to be hard to use. We have a lot of experience here to draw on, after all, although we need to make sure we build a horse with this one, not a camel!

  6. #6
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleMac Export Module
    AndyH's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,445
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: JSON object idea

    Sounds like a good idea to me.
    Andy H @ ovine.net
    Awful Jokes - a new cartoon every day: http://awful.ovine.net/
    Ovine's games: http://www.ovine.net

Similar Threads

  1. [Beta] JSON Object
    By LB in forum Extension Development
    Replies: 49
    Last Post: 8th January 2015, 06:03 PM
  2. [Request/Beg] JSON Object
    By DizzyDoo in forum Extension Development
    Replies: 25
    Last Post: 16th July 2013, 03:06 AM
  3. [Request] JSON Object
    By ItsAUsername in forum Extension Development
    Replies: 33
    Last Post: 13th May 2013, 07:34 PM
  4. JSON Object ?
    By Rushino in forum Extension Development
    Replies: 0
    Last Post: 3rd April 2013, 06:48 PM
  5. [NEW] JSON Generator and Editor
    By RickyRombo in forum Extension Development
    Replies: 0
    Last Post: 23rd August 2011, 10:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •