Ugly Stool Rotating Header Image

My First JSON Document

I am writing my first JSON document (welcome to the party), and looked for tools to help me write it.  I want a tools to validate the document’s syntax, and tell me when I am doing the wrong thing.

I didn’t find a whole lot.  I settled on the Perl library JSON::XS, which comes with the command line tool json_xs for pretty printing and validation (kind of like xml_pp from XML::Twig) .  I used js2-mode for EMACS to write the document.

My biggest disappointment is that JSON makes trailing commas optional.  JSON parsers can optionally support or not support this construct.  This is wrong.  It requires more code to not add the comma, then it does to just add the comma all the time.  The trailing comma is supported to assist with the machine generation of code.  For shame JSON, for shame!

This syntax is not universally supported.

{
    "abc": 123,
    "def": 456,
    "ghi": 789,
}

Strip the trailing comma for better parser support.  In other words, this really is the standard format.

{
    "abc": 123,
    "def": 456,
    "ghi": 789
}

Comments are closed.

Page optimized by WP Minify WordPress Plugin