r/ProgrammerHumor • • 15d ago • Bravo 1

Meme commentsInJson

Post image
6.0k Upvotes

202 comments sorted by

View all comments

967

u/nameless_pattern 15d ago • Bravo

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

268

u/tokalper 15d ago

I Just create some fields names "__"

150

u/metaglot 15d ago

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

92

u/tokalper 15d 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.

65

u/the-liquidian 15d ago

JSONC was created for this.

86

u/AnotherPillow 15d ago

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

9

u/Devatator_ 14d ago

C#'s System.Text.Json will reject comments by default but you can configure it to accept and even parse them if you want to read their content

19

u/Slight-Violinist-575 14d ago

Comments are for humans lmao

9

u/Devatator_ 14d ago

I mean someone could make some fucked up preprocessor using comments

8

u/Slight-Violinist-575 14d ago

I am sure someone could, and I am sure someone eventually will, and we will pay for it

→ More replies

5

u/Turbulent_Stick1445 14d ago

There is a use case for reading comments (though it really needs to be optional) which is if your code is editing the JSON rather than just getting information for it.

eg:

configObject = loadJSON(".config/myapp/settings.json");
configObject.enableCrashes = true;
configObject.write(".config/myapp/settings.json");

But that means a fairly ugly JSON parser that would have to store a lot of positional information. I mean, it can be done, but...

→ More replies (4)
→ More replies (2)
→ More replies (6)

58

u/DiamondDramatic9551 15d ago

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

7

u/YoghurtFlan 14d ago

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

20

u/nameless_pattern 14d ago edited 14d 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 14d ago

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

19

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

14

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

7

u/stipo42 14d ago

Then your marshalling library throws "unexpected key"

→ More replies (4)

13

u/john_the_fetch 14d ago

But they want it in line.

Like :

i added the prod key here until staging is fixed

{key:"omgIsThisYourProdKey?fs*dsjs"}

→ More replies (3)

6

u/mothzilla 14d 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)

16

u/Turbulent_Stick1445 14d 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 (8)

5

u/Successful-Active-21 14d ago

but it will collide with someone's field comments

24

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

4

u/YesterdayDreamer 14d ago

Schema validation is a thing

→ More replies (1)

4

u/thecrius 14d ago

That's the way.

→ More replies (5)