r/ProgrammerHumor • • 4d ago • Bravo 1

Meme commentsInJson

Post image
5.8k Upvotes

205 comments sorted by

View all comments

926

u/nameless_pattern 4d ago • Bravo

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

257

u/tokalper 4d ago

I Just create some fields names "__"

144

u/metaglot 4d ago

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

91

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

63

u/the-liquidian 4d ago

JSONC was created for this.

84

u/AnotherPillow 4d ago

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

9

u/Devatator_ 4d 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

18

u/Slight-Violinist-575 4d ago

Comments are for humans lmao

9

u/Devatator_ 4d ago

I mean someone could make some fucked up preprocessor using comments

8

u/Slight-Violinist-575 4d 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 4d 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)

56

u/DiamondDramatic9551 4d ago

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

7

u/YoghurtFlan 4d ago

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

20

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

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

19

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

14

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

7

u/stipo42 4d ago

Then your marshalling library throws "unexpected key"

→ More replies (4)

12

u/john_the_fetch 4d 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 4d 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)

15

u/Turbulent_Stick1445 4d 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)

4

u/Successful-Active-21 4d ago

but it will collide with someone's field comments

24

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

4

u/YesterdayDreamer 4d ago

Schema validation is a thing

→ More replies (1)

4

u/thecrius 4d ago

That's the way.

→ More replies (5)