Cole StrilerCole Striler

By Cole Striler. 

Why are comments not allowed in JSON?

October 10, 2022

JSON is data-only, meaning traditional comments in code are not supported. I.e:

{
  # note: this is not allowed
  "title": "Red Addidas Shoes",
  "price": 50
}

Even though .json files are used frequently in Javascript and other applications, it’s important to not confuse them with code files.

I like to think of JSON data as being more of a data store than it is a piece of code that gives clear instructions.

Code files are designed to be read by humans and comments help make the code readable to other humans. JSON is designed to be parsed by a computer so comments just get in the way and may cause parsing errors.

There is one work-around to using comments in JSON, which I talk more about in this post.


By Cole Striler. 

If this was helpful or you have any other questions, reach out on Twitter! Happy to help.

© 2022, Cole Striler