Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Simplify JSON

  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simplify JSON

    JSON likes to call itself "The Fat-Free Alternative to XML" but is it really as healthy as it proclaims to be?

    I think there are ways to make it smaller and more human-readable while preserving the excellent machine-readability

    A few things I thought of while parsing JSON:
    • Why put quotes around the key? Have you ever seen a key with whitespace or curly braces? (even if you did you can escape them) ==> Let's remove the quotes
    • An id-value pair is separated from others by a comma. In a pair it is always obvious (because of formatting) what is the key and what is the value (unless one of either 2 is missing). So let's get rid of the colon.
    • Everything in JSON is a string. Let's not pretend otherwise. ==> Enclose all values in double quotes, or make quotes optional entirely.
    • For a better type system we could think of optional prefixes to let the reader know what data type it should be converted to, stuff like:
      • {mydata x"1F A9 0C"} for hex
      • {mynumber d"824"} for a decimal integer
      • {mynumber ld"46,319,878,234"} for a long 64-bit decimal int.
      • {mynumber f"100.29" } for a float

      If the parser or target language can't process the type it stays a string. This sounds a lot more flexible and extensible than the current type system.


    Lets see an example from JSON.org. Before:
    Code:
    {"menu": {
       "id": "file",
       "value": "File",
       "popup": {
          "menuitem": [
             {"value": "New", "onclick": "CreateNewDoc()"},
             {"value": "Open", "onclick": "OpenDoc()"},
             {"value": "Close", "onclick": "CloseDoc()"}
          ]
       }
    }}
    After:
    Code:
    {menu {
       id "file",
       value "File",
       popup {
          menuitem [
             {value "New", onclick "CreateNewDoc()"},
             {value "Open", onclick "OpenDoc()"},
             {value "Close", onclick "CloseDoc()"}
          ]
       }
    }}
    Without quotes:
    Code:
    {menu {
       id file,
       value File,
       popup {
          menuitem [
             {value New, onclick CreateNewDoc() },
             {value Open, onclick OpenDoc() },
             {value Close, onclick CloseDoc() }
          ]
       }
    }}
    Obviously there are a few edge cases I can think of which need to have their behavior defined. But real-world examples of those are scarce.

    I've looked into an alternative like YAML, but I dont want to leave delimiters entirely (just the superfluous ones). Relying on indentation brings up new issues and limitations, and it makes nested data bigger. It also is more difficult to parse.

    Thoughts?
    Last edited by Hulkiedo; 01-24-2013 at 03:38 AM.

  • #2
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've changed my mind on adding newline as a delimiter (with the same functionality as comma), because it makes parsing harder. For the rest I stand by my points.
    Last edited by Hulkiedo; 01-24-2013 at 03:01 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
    •