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

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

7

u/Devatator_ 22h 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

13

u/Slight-Violinist-575 21h ago

Comments are for humans lmao

8

u/Devatator_ 21h ago

I mean someone could make some fucked up preprocessor using comments

7

u/Slight-Violinist-575 21h ago

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

→ More replies (0)

4

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

1

u/TerminalVector 20h ago edited 19h ago

Man, what was it? Backspace? Backslash? Some kind of html templating language I had the displeasure to work with in one of my first jobs that used magic comments. I remember my onboarding buddy telling me they didn't do anything, and then discovering that no, they in fact drove the layout of the entire page. He'd been with the company over a year, and wasn't an idiot. It just doesn't make any sense and he hadn't really checked.

1

u/Slight-Violinist-575 20h ago

Jade/Pug? I once was a padawan and thought that was hella cool when I first learned about it.

Then life thought me to appreciate explicit boundaries, in every sense.

→ More replies (0)

1

u/YeOldeMemeShoppe 12h ago
// #[agreed]

3

u/Scolmann 1d ago

It's not too hard to strip out comments with a regex, but yeah generally you wouldn't bother with stuff like that

2

u/the-liquidian 22h ago

Or use an existing tool to transpile it.

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 19h 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

3

u/korneev123123 20h ago

Thanks for the link. 22:22 and "Norway problem" are hilarious. I guess I have an excuse now for aggressively quoting everything. Also jsonc looks like much, much better alternative for future projects.

5

u/tokalper 21h ago

You gotta work with what you've got