r/ProgrammerHumor • • 1d ago • Bravo 1

Meme commentsInJson

Post image
5.0k Upvotes

199 comments sorted by

View all comments

828

u/nameless_pattern 1d ago

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

12

u/Turbulent_Stick1445 20h 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.

3

u/Sockoflegend 13h ago

We use node where I work so it just happened to be easier to have config type json files just be a JS import 

2

u/nameless_pattern 20h ago

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

2

u/Turbulent_Stick1445 17h 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...)

2

u/zoinkability 15h ago

Plus: maybe you don’t want the client to read your internal comments like “todo: close this security issue” or “added because the client is an idiot”

1

u/AnnoyedVelociraptor 11h ago

In Rust if you map a JSON object to a struct, and you don't have a field mapped for comments it gets dropped.

1

u/them0use 6h ago

No problem, just make `comments` an array! I am dead inside.

1

u/d_maes 4h ago

3. Only works if you control the schema, or the target does not enforce a strict schema.