I accidentally used YAML.parse instead of JSON.parse, and it… worked?

submited by
Style Pass
2022-01-24 00:30:04

Yesterday, I was working on a project that had to parse a JSON file. I’d named the file config.yml instead of config.json by mistake, so when it came to filling in this function below, autopilot took over and did this:

Fast-forward to today morning, as I’m reviewing my pull request I see the mistake and wonder… why didn’t this break my tests?

YAML can therefore be viewed as a natural superset of JSON, offering improved human readability and a more complete information model. This is also the case in practice; every JSON file is also a valid YAML file. This makes it easy to migrate from JSON to YAML if/when the additional features are required.

Leave a Comment