I accidentally used YAML.parse instead of JSON.parse, and it… worked?
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:
def config+ YAML.load(File.read('config.yml')) end
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?
That, dear reader, is the story of how I learnt that YAML is a superset of JSON.
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.
(from YAML: Relation to JSON)