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

krutik khatri

Hii You can also use https://onlinejsontools.org/ for json validator,beautify,minify,xml,yaml,CSV,bson,plain text,base64,tsv. Do checkout this site!

This is a unique place for fashionable women’s clothing and accessories. We offer our clients women’s clothing, jewelry, cosmetics and health products, shoes, bags and much more. https://fas.st/Ujfha

https://liveone9.com/

You: Great. Do this. But can I ask what you’ve been doing up to date? Why do you think you aren’t getting more comments? Your reader: Well, I haven’t tried what you just proposed, and I think it’s a great solution. So far, I’ve been wrapping up my posts nice and tightly but it feels like I’m cutting off the circulation, 카지노사이트

Leave a comment

Notify me of replies by email.