r/ProgrammerHumor • • 13d ago

Meme commentsInJson

Post image
6.0k Upvotes

202 comments sorted by

View all comments

175

u/pregister 13d ago

66

u/Chasar1 13d ago

This solves every gripe I have with json

28

u/foxsimile 13d ago

Yes. I’m struggling to think of an unaddressed complaint, which is rare for me.

13

u/EuenovAyabayya 13d ago

Supported on all your platforms?

5

u/foxsimile 13d ago

I just kind of took the lack of universal support one as a given ¯_(ツ)_/¯

4

u/MaximRq 13d ago

Unfortunately my train platform doesn't support it

7

u/Librarian-Rare 13d ago

Fr, why isn't this the whole world now??

5

u/YeOldeMemeShoppe 13d ago

It also actually solves edge cases where the JSON spec cannot read valid JSON.

2

u/innociv 13d ago

... I just don't even think about putting \\n at the end of a line and stuff. I never really had a gripe. I guess I've just been someone who is good at following instructions and I don't question this stuff.

9

u/mrheosuper 13d ago

Wait there are json1, json2, json3 and json4 ?

11

u/lachlanhunt 13d ago

No, it was named JSON5 as a subtle nod to HTML5, because it fixed a lot of stuff with the original format when using it for use cases like config files.

→ More replies (2)

1

u/Western-Anteater-492 13d ago

That's the great thing bout json5! It's so great it completely jumps 1 to 4.

22

u/audigex 13d ago

Or YAML

… because JSON is valid YAML syntax, for some reason

18

u/AlwaysHopelesslyLost 13d ago

Because yaml is just a bolt on extension of JSON. It is json but it lets people omit most of the critical control structures in favor of inferring from whitespace characters.

13

u/Habba 13d ago

I really hate yaml so much. It's both terrible to write as a human, super easy to get wrong indentation on stuff and it's famously horrible to parse.

4

u/gogliker 13d ago

No getting parsed as Norway was my all time favorite with YAML parsers. I think TOML is better though

1

u/Habba 13d ago

TOML is indeed better for a lot of things, especially config. Not sure about other places yaml gets used, like in defining CI pipelines. I hate yaml there too however, it always takes me 3 times to get the right incantation for a variable interpolation.

I think something like Jenkins is better there, since its actual code, but Groovy also sucks.

1

u/caboosetp 13d ago

 omit most of the critical control structures in favor of inferring from whitespace characters

So what you're saying is that yaml is python for json.

9

u/voyagerfan5761 13d ago

I did not need to know that.

Someone fetch me a time machine…

1

u/Turbulent_Stick1445 13d ago

WHY AM I NOW ONLY HEARING ABOUT THIS?

(From what I'm reading it's MOST JSON is valid YAML, but there are differences: JSON allows tabs for indenting, and has some slight differences with escaping - like "\/" is valid JSON but invalid YAML. Surrogate pairs in JSON written like "\uD83D\uDE00" need to be written as "\U0001F600". Bottom line, be aware there are differences, but the main feature of YAML's JSON compatibility is that if the YAML indenting thing isn't very readable to you, you can just write stuff in a more JSON-like way, which, after decades of C and Java and Javascript programming, most of us are used to.)

1

u/Hax0r778 12d ago

JSON doesn't have indenting?

I mean, it fully ignores white-space outside of strings so you could add whatever random tabs you want in your JSON file. But I wouldn't call it indenting if it has no meaning and is ignored by all valid JSON parsers...

1

u/Turbulent_Stick1445 12d ago

JSON has optional indenting where the tab is just generic white space you can use without it impacting anything. You do not need to indent something in JSON, and it's only meaningful to human readers if you do.

However, tabs ARE meaningful in YAML, under certain circumstances they affect how the file is parsed.

→ More replies (3)
→ More replies (2)

2

u/enigma_0Z 13d ago

Idk this looks like yaml with extra steps for the most part. You can write bastardized json with bare identifiers etc in yaml and it parses fine. Including iirc curries and squares to replace the white space and “-“ indentation notation if you want.

Edit: Then again if you are writing a config file for humans (ie why you want comments in it), JSON (with or without comments) maybe is not the right choice to start with /IMO

→ More replies (1)