Comments in JSON

JSON does not have comments. A JSON encoder MUST NOT output comments. Douglas Crockford - creator of json http://tech.groups.yahoo.com/group/json/message/152

Want to use comments in JSON even though Douglas doesn’t want you to :)

Using ini, apache, xml, html or // comment formats invalidate your JSON files

invalid_comments.json

{
    "name": "Jack (\"Bee\") Nimble", //varchar
        "format": {
            "type":       "rect", //varchar - max 4 characters
            "width":      1920, //int
            "height":     1080, //int
            "interlace":  false, //boolean
            "frame rate": 24 //int
        }
}

As Douglas stated, JSON has no offical support for comments, but it doesn’t mean you can’t add them in other ways

The best way I’ve found to add comments into JSON is to add _comment style elements - after the element your commenting on - into the JSON. Refer below for a valid JSON file with comments.

valid_comments.json

{
    "name": "Jack (\"Bee\") Nimble", 
        "_name_comment":"varchar",
        "format": {
            "type":       "rect", 
            "_type_comment": "varchar - max 4 characters",
            "width":      1920, 
            "_width_comment": "int",
            "height":     1080, 
            "_height_comment": "int",
            "interlace":  false, 
            "_interlace_comment": "boolean",
            "frame rate": 24,
            "_frame_rate_comment": "int"
        }
}

Note:

  • Make sure your app ignores the _comment elements
  • Use jsonlint.com to validate your JSON

Let me know if you have a better way to do valid comments in JSON

Justin Kelly

Justin Kelly

Web Developer, Business Analytics, Data Engineer specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly

Comments

I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is wonderful, the articles is really excellent D. Good job, cheers edcaeaadbfccbfed

Excellent blog right here! Also your site lots up very fast! What web host are you the use of? Can I get your affiliate hyperlink for your host? I desire my website loaded up as quickly as yours lol keddbbeadfgegcdk

Hey very nice blog!! Man .. Excellent .. Amazing .. I will bookmark your site and take the feeds alsoI’m satisfied to find a lot of useful info right here within the post, we’d like develop extra strategies in this regard, thanks for sharing. beeecckkbabdkeag

Some truly select blog posts on this web site , saved to fav. dkdebedekbekbffk

This kind of game gives a real experience of building a kccaeddcggkfdkda

It is also possible that Zynga’s chosen advertising network is to blame if we kbdaabbgkebedakf

Just wanna input on few general things, The website pattern is perfect, the subject material is real excellent. Believe those who are seeking the truth. Doubt those who find it. by Andre Gide. bbkgbdddeacebccf

I loved your blog article. Really Cool. kkfbckgagefagegk

I really enjoy reading on this website, it holds great articles. Don’t put too fine a point to your wit for fear it should get blunted. by Miguel de Cervantes. edfdbgeaffkdfebb

Leave a comment

Notify me of replies by email.