News for hackers. Stuff that matters.
Re:JSON is not a YAML subset (2022) by pavel_lishin on Friday August 01, 2025 @06:32PM (#44763176)
> Regardless of whether YAML 1.2 has been (or will be) widely adopted, it does not help those who want to parse a JSON document with a YAML parser.

Who are these hypothetical lunatics?

Re:JSON is not a YAML subset (2022) by makeitdouble on Friday August 01, 2025 @08:00PM (#44763736)
It works in most trivial cases, so I'm assuming it's widely done irl.

Imagine building some small app that reads external config file. You personally only care about yaml files, but your avid users ask for official json support as well because of a few of their files.

It's not high priority, but as you remember the old saying, json is just a subset, so you try a bunch of files, confirm it works well enough, and decide to pipe JSON files to your yaml parser as well. Done and done.

And it's not so big block of code or anything that jumps at the users, the dev just happens to share a parser between formats.

Re:JSON is not a YAML subset (2022) by randallsquared on Friday August 01, 2025 @07:14PM (#44763479)
Anyone who wants to convert a piece at a time to yaml, but would prefer to just use a single parse step (as suggested by one of the quoted bits in the article). It's a niche case, but sensical.
Re:JSON is not a YAML subset (2022) by zamalek on Friday August 01, 2025 @07:47PM (#44763662)
You want to use a machine to create a document for something that accepts JSON. e.g. Something I was playing around with was having a github workflow that generates a github workflow. Or generating docker compose files.
Re:JSON is not a YAML subset (2022) by coderjames on Friday August 01, 2025 @07:07PM (#44763434)
> those who want to parse a JSON document with a YAML parser.

I've done it. We already had a YAML parser in an internal library I maintain since we were already ingesting YAML files for other reasons, so when we later added new files for a different reason that someone decided should be in JSON instead, it was easier and cleaner to keep using the existing YAML parser we already had incorporated rather than add a separate JSON parser along side it.

Re:JSON is not a YAML subset (2022) by MyOutfitIsVague on Friday August 01, 2025 @08:21PM (#44763857)
Ruby on Rails has a databases.yml that is preprocessed by ERB. I often do something like:

    field: <%= File.read('/foo/bar').to_json %>
Though I have myriad criticisms of YAML, this article's arguments are not a concern at all if you can ensure that your YAML parser always uses 1.2 regardless of any %YAML directive.
Re:JSON is not a YAML subset (2022) by 0xbadcafebee on Friday August 01, 2025 @08:57PM (#44764067)
As someone who has written a lot of YAML-compatible software, this is my biggest takeaway: every single YAML-parsing tool is incompatible with each other (in some way). If two tools work together, it's an accident. They will work for a while until someone tries to do something with one tool that the other tool doesn't like.

If all you do with YAML is serialize data, from one tool, to the exact same tool, it's fine. For all other purposes you should seek a different data format (if you don't want to deal with the eventual bugs).

(note that I don't mean parser/library, I mean tool. the tool using the library will often use or not-use certain options which increases the complexity of the interactions and leads to more possible failures)

Re:JSON is not a YAML subset (2022) by osigurdson on Friday August 01, 2025 @08:56PM (#44764065)
Kubernetes is a good example. Objects can be read / written as json or yaml interchangeably.
Re:JSON is not a YAML subset (2022) by antonvs on Friday August 01, 2025 @09:22PM (#44764189)
It’s not an example at all. It uses different parsers and renderers for each format.
Re:JSON is not a YAML subset (2022) by osigurdson on Saturday August 02, 2025 @10:53AM (#44768094)
The parent comment asks the question "Who are these hypothetical lunatics?". I don't know what today's Kubernetes parser does but it seems plainly obvious that Kubernetes would be a consumer of "YAML as JSON superset" parser if it exists. It isn't as though users are expressing different things with JSON than they are with YAML.
Re:JSON is not a YAML subset (2022) by ethan_smith on Friday August 01, 2025 @09:20PM (#44764181)
Configuration systems like Kubernetes and Docker Compose use YAML parsers that accept JSON as input, allowing users to write in either format without changing the tooling.
Re:JSON is not a YAML subset (2022) by dathinab on Saturday August 02, 2025 @12:31PM (#44768951)
but the things is there is a difference between

1) a parser which can handle both (based on detecting both and then switches the parsing depending on it)

2) a parser which is made for YAML and happens to be able to parse JSON

Re:JSON is not a YAML subset (2022) by williamjackson on Friday August 01, 2025 @10:33PM (#44764467)
I don’t like writing YAML. I like writing Python. So I write Python that generates YAML config files. JSON is in the standard library but YAML isn’t. So I generate JSON and name the file “file.yaml”.

GitHub Actions, Dependabot, and Docker Compose never complain.

Re:JSON is not a YAML subset (2022) by jaredklewis on Saturday August 02, 2025 @02:55AM (#44765369)
For real. You can find hardened, optimized JSON parsers for every runtime worth running. Hard to think of why you would want to avoid all those JSON parsers and use a YAML one to parse JSON.
Re:JSON is not a YAML subset (2022) by dathinab on Saturday August 02, 2025 @12:30PM (#44768945)
people stuck with sub-par tooling

(weather that's because of laziness, better tooling not being available/integrated, not know, not being usable or them being stuck on a ideological delusion where they insist on not using it doesn't really matter)

like sub-par tooling is one of the 2 main reason of when it comes to problems with config or data serialization format (bugs, strange edge cases, etc.)

the other is people obsessing with handling things the exact same way, which might looking similar from far away but have major different details/constraints/dynamics when you look closely at them. (like config parsing vs. data deserialization vs. ad-hoc languages on top of a config format)

Re:JSON is not a YAML subset (2022) by pavel_lishin on Saturday August 02, 2025 @01:39PM (#44769602)
Ah, there y'all are.