How do I add comments to JSON? [C#/.NET Code]

JSON is not intended and does not support comments by design, which means that comments in the form // ... or / * ... * / are not allowed in JSON files. But there is a workaround for adding comments to JSON files. To do this, you need to add an element to your JSON file, such as "_comment," which will contain your comment. The JSON API endpoint must ignore this particular JSON comment element. In this JSON comment example, we have included two comment elements in the JSON data, which you can see in the Content tab. The C#/.NET code was automatically generated for the JSON Comment example.

Source JSON

JSON Comments Summary
  • JSON does not support comments by design
  • You can add comments in JSON as custom elements
  • "//" and "_" are the most commonly used comment prefixes
  • You can use JSON preprocess that remove comments before parsing
  • Microsoft JSONC format has built-in support for comments
Trusted by 850,000+ API Developers