How can I add comments in JSON?

Learn how to work around the lack of comment support with tips for creating structure-specific comments that won’t be rejected by the compiler.

By Jeremy McPeak
September 6, 2016

Web developers at any skill level will recognize how important proper documentation is in their code. While JSON has become much more than the data interchange format it was originally designed for, it does not yet permit commenting. So what is a JSON developer to do?

McPeak will teach you two workarounds to this problem as well as the advantages and drawbacks to each. The first option presented is an external tool, JSMin. By stripping the code before publishing for production, comments are removed with the added bonus of smaller file sizes. However this is not ideal for those who work with dynamically generated JSON. As an alternative, McPeak shows us how to use built-in tools to make structure-specific comments that won’t be rejected by the compiler.

Learn faster. Dig deeper. See farther.

Join the O'Reilly online learning platform. Get a free trial today and find answers on the fly, or master something new and useful.

Learn more

Take the next step with JavaScript with our Beginning JavaScript Learning Path.


Jeremy McPeak is a self-taught programmer who began his career tinkering with websites in 1998. He is the author of Beginning JavaScript, 5th Edition, JavaScript 24-Hour Trainer, and co-author of Professional Ajax, 2nd Edition. He also contributes to Tuts+ Code (code.tutsplus.com), providing articles, video tutorials, and courses on JavaScript, C#, ASP.NET, and PHP. He is currently employed by an oil and gas company, building in-house conventional and web applications.

Post topics: Web Programming
Post tags: Questions
Share:

Get the O’Reilly Web Newsletter

Get the O’Reilly Web Newsletter