Tagged as: json web

The JSON specification lacks a provision for comments, but that doesn't mean that you can't have comments!

Since it doesn't matter if your JSON file has additional data within it, you can simply add additional keys that provide information. As an example, take this file:

{
    "name": "Pie",
    "id": "pi-56hf9z",
    "category": "food,pastry"
}

I can add some comments like so:

{
    "_comment_name_": "name of the item",
    "name": "Pie",
    "_comment_id_": "a unique identifier",
    "id": "pi-56hf9z",
    "_comment_category_": "a comma-seperated list of categories",
    "category": "food,pastry"
}

All that matters with your comments is that the name is not used by any other item. Adding a unique prefix is one simple way to achieve this. In the example above, my prefix is _comment_.