r/ProgrammerHumor • • 7d ago • Bravo 1

Meme commentsInJson

Post image
6.0k Upvotes

205 comments sorted by

View all comments

965

u/nameless_pattern 7d ago • Bravo

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

267

u/tokalper 7d ago

I Just create some fields names "__"

150

u/metaglot 7d ago

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

92

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

JSONC was created for this.

86

u/AnotherPillow 7d ago

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

9

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

Comments are for humans lmao

9

u/Devatator_ 7d ago

I mean someone could make some fucked up preprocessor using comments

8

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

57

u/DiamondDramatic9551 7d ago

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

7

u/YoghurtFlan 7d ago

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

20

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

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

19

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

14

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

7

u/stipo42 7d ago

Then your marshalling library throws "unexpected key"

→ More replies (4)

13

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

but it will collide with someone's field comments

24

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

4

u/YesterdayDreamer 7d ago

Schema validation is a thing

→ More replies (1)

4

u/thecrius 7d ago

That's the way.

→ More replies (5)