r/ProgrammerHumor • • 8d ago • Bravo 1

Meme commentsInJson

Post image
6.0k Upvotes

205 comments sorted by

View all comments

Show parent comment

22

u/audigex 8d ago

Or YAML

… because JSON is valid YAML syntax, for some reason

18

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

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

1

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

I did not need to know that.

Someone fetch me a time machine…

1

u/Turbulent_Stick1445 8d 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 7d 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 7d 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.

1

u/FerusGrim 6d ago

What the person was saying is that JSON doesn’t “have” optional indentation. It’s just meaningless, and ignored.

1

u/Turbulent_Stick1445 6d ago

OK, I'm still unsure what was read in my original comment that the GGP was generating a warning message.

Point was simply if you indent lines of JSON with tabs, you're going to run into trouble if parsing it with a YAML parser. Whether JSON considers indenting to be significant is really irrelevant to that point, people indent JSON just as they indent Java, C, etc. I never wrote anything that I feel can be remotely interpreted as "If you indent JSON, JSON will consider the indenting to be significant and interpret it differently" but maybe you're seeing something there?

1

u/FerusGrim 6d ago

I don't think you're being misunderstood. I, and I'm pretty sure everyone else, already knows what you mean. It may be a bit pedantic, but the point being made is just that the way you were referring to using indentation was as if it was some property that JSON had, or was capable of. That's why I used "have" in quotes. But JSON doesn't really "have" the "feature" of indentation, it's just... uncaring of it.

1

u/thecrius 7d ago

A configuration language in which spaces are determining it's meaning

Fuck. That.

1

u/audigex 7d ago

To be fair I’ve always figured YAML is more aimed at “very easy to read by humans, but should be primarily read and written by the computer”

It feels more like a computer-focused config language that happens to be convenient to read