Cole StrilerCole Striler

By Cole Striler. 

How to use comments in JSON

October 10, 2022

Although traditional comments are not allowed in JSON, there is one work-around.

JSON is data-only, meaning something like this won’t work:

{
  # note: this is out of stock
  "title": "Red Addidas Shoes",
  "price": 50
}

Instead, we can add a new data element to the JSON and just ignore it when we read the JSON into our code.

{
  "_note": "this is out of stock"
  "title": "Red Adidas Shoes",
  "price": 50
}

If you want to learn more about why comments aren’t allowed in JSON, checkout 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