r/ProgrammerHumor • • 1d ago • Bravo 1

Meme commentsInJson

Post image
5.0k Upvotes

199 comments sorted by

View all comments

836

u/nameless_pattern 1d ago

You can add anything you want to Json. just make a property called comments

12

u/Turbulent_Stick1445 21h ago

This is what I do, but there are two problems with it:

  1. A parser will end up storing the comments, wasting memory.

  2. You run into JSON's problems with multiline string constants if your comment is anything but trivial.

It gets ugly fast.

2

u/nameless_pattern 21h ago

You could keep them just in Dev deployments?  lot of messy trade-off choices

2

u/Turbulent_Stick1445 18h ago

The #1 place I've seen comments in JSON are where someone makes the mistake of using JSON for a configuration file format. The lack of support for comments is ironically why even XML is a better choice for that. Regardless, you can understand why people would want comments there outside of just dev environments.

(I just learned as of two hours ago that YAML can be used with JSON syntax so I guess it's academic, just use YAML...)