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.

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.

Article image: Screenshot from "Adding comments in JSON"