Comments in the form // ... or / * ... * / are not allowed in JSON, but you can have a special element in your JSON file called "_comment", for example, that will contain your comment. The JSON API endpoint must ignore this special JSON comment element. See an example of including comments in JSON below on the Content tab. The C#/.NET code was automatically generated for the JSON Comment example.
Can JSON contain comments?
Comments in the form //, #, or / * * / that are used in popular programming languages are not allowed in JSON. As a workaround, you can add comments as JSON data attributes for the custom elements in your JSON file, as shown in the examples below.
Why doesn't JSON support comments?
Douglas Crockford, who popularized the JSON data format, describes the reason why he removed comments from JSON: I removed comments from JSON because I saw people using them to store parsing directives, which would break compatibility.
Therefore, the only option for adding comments to JSON is a workaround to use custom elements to store comments in a JSON file.
Adding JSON comments as custom JSON data attributes
Since JSON is a textual format for storing and exchanging data using key-value pairs, we can actually use comments as data pairs. In this JSON comment example, we have added the comment as a custom "_comment" element. We use the underscore as a convention to distinguish comments from the rest of data. This comment element will be parsed and processed just like any other JSON data in your applications. Your server must ignore this special element when processing the received JSON.
JSON does not allow duplicate object keys, so in order to have multiple comments in a JSON file, you need to add a unique letter or number to your element to make it valid. To make it easier for other developers to read comments in your JSON file and to make it easier to programmatically process such a JSON file (for example, to remove comment nodes), it is recommended that you use the "//" convention as the basis for comment names.
Multiple JSON Comments
"Customer": "Eric Sweet",
"//first_comment": "The first comment.",
"//second_comment": "The second comment."
Another option to have multiple comments in the JSON file and avoid the duplicate keys problem is to add comments to the nested JSON elements as shown in the example below.