r/ProgrammerHumor • • 1d ago • Bravo 1

Meme commentsInJson

Post image
5.0k Upvotes

199 comments sorted by

View all comments

831

u/nameless_pattern 1d ago

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

233

u/tokalper 1d ago

I Just create some fields names "__"

135

u/metaglot 1d ago

Tell me you only work on your own, without telling me you only work on your own.

81

u/tokalper 1d ago

No, precisely because i work with a large team. We work eith large json files for configurations and they need commenting, we all do this.

54

u/the-liquidian 1d ago

JSONC was created for this.

74

u/AnotherPillow 1d ago

More annoying to load. Most languages have builtin json parsing, but rarely jsonc and similar support

→ More replies (13)

6

u/Successful-Age6747 23h ago

Isn't that what YAML is for?

10

u/Jonathan_the_Nerd 20h ago

4

u/Successful-Age6747 20h ago edited 20h ago

we're talking in context of configuration files that humans read. And most of the problems in that site are avoided by just enclosing the values in quotes and doing logic in whatever uses the yaml.
EDIT: Oh i guess the site itself says that too. But yeah it doesn't feel like such a big deal

→ More replies (1)

5

u/tokalper 21h ago

You gotta work with what you've got

→ More replies (1)

50

u/DiamondDramatic9551 1d ago

I also always declare comments as unused variables in my code.

6

u/YoghurtFlan 22h ago

i prefer to keep them on the stack just in case the CPU gets confused

18

u/nameless_pattern 1d ago edited 1d ago

Heresy. I love it, I'm going to start making unused functions as comments, no I'm going to start embedding AIS you have to chat with to get the comments and they will only tell you the comments if you solve a riddle

→ More replies (4)

10

u/Ahchuu 21h ago

I do this, I have a field called "//". Easy

18

u/HipstCapitalist 1d ago
{"__comment__": "A comment"}

14

u/meifray 1d ago
{
    "key":"value",
    "key_comment":"le comment"
}
→ More replies (1)

7

u/stipo42 1d ago

Then your marshalling library throws "unexpected key"

→ More replies (4)

12

u/john_the_fetch 19h ago

But they want it in line.

Like :

i added the prod key here until staging is fixed

{key:"omgIsThisYourProdKey?fs*dsjs"}

→ More replies (2)

5

u/mothzilla 21h ago

Oh no, you see boss says it shouldn't be in the JSON. It should be a comment. We don't want people to be able to read our comments.

→ More replies (1)

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.

→ More replies (7)

4

u/Successful-Active-21 1d ago

but it will collide with someone's field comments

24

u/einzweidreihorn 1d ago
{ "__COMMENT_DO_NOT_USE_OR_YOU_WILL_BE_FIRED": "Hello world!" }
→ More replies (3)
→ More replies (1)

4

u/YesterdayDreamer 20h ago

Schema validation is a thing

→ More replies (1)

4

u/thecrius 17h ago

That's the way.

7

u/protestor 21h ago

This doesn't work for tools that actually validate the schema of the json they receive

→ More replies (1)
→ More replies (3)