https://www.freecodecamp.org/news/json-comment-example-how-to-comment-in-json-files/
If you’re having trouble adding comments to your JSON file, there’s a good reason: JSON doesn’t support comments.
“I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability,” writes Douglas Crockford, who popularized the text-based data format.
However, there’s a workaround. And that’s what this article is about: how to add comments to your JSON file.
Add Data as Comments
A way to skirt around the comments issue is to add data to your JSON file that function as comments.
Let’s go through an example, starting with this information in our JSON file:
{
"sport": "basketball",
"coach": "Joe Smith",
"wins": 15,
"losses": 5
}
Now let’s add another key-value pair to serve as our comment, which you can see in the first line in the code below:
{
"_comment1": "this is my comment",
"sport": "basketball",
"coach": "Joe Smith",
"wins": 15,
"losses": 5
}
Here’s another example. This time, we use two underscores at the start and end of the key:
"__comment2__": "this is another comment",
The underscores help to differentiate the comment from the rest of the data in our file.
No comments:
Post a Comment