3 ms·
That’s not true; YAML is completely seperate.
by robin_reala 11y ago
That’s not true; YAML is completely seperate.
- bjacobel 11y agoCorrect. YAML and JSON can be parsed into the same tree structure but are completely separate syntaxes.
- icebraining 11y agoNo, they aren't. From the YAML site [emphasis mine]: "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." http://yaml.org/spec/1.2/spec.html#id2759572 http://yaml.org/spec/1.2/spec.html#id2759572 You can parse any JSON file using a YAML parser.
- robin_reala 11y agoI … OK, I recind my earlier statement! TIL :)
- icebraining 11y agoNo, it's not. See my post downstream. Every JSON file is a valid YAML file. Example: using PyYAML to parse the JSON file from above: >> import yaml >> val = yaml.load('{"extensions": ["cpp", "cc", "cxx", "c++", "h", "hpp", "hxx", "h++", "inl", "ipp"]}') >> print val {'extensions': ['cpp', 'cc', 'cxx', 'c++', 'h', 'hpp', 'hxx', 'h++', 'inl', 'ipp']}
- BillinghamJ 11y agoWow, interesting. Why do people use YAML syntax then? I find JSON much simpler, less ambiguous. Much prefer JSON for configuration over YAML.
- icebraining 11y agoMostly, I'd say people who prefer YAML-specific syntax (myself included) think it's generally more readable and easier to write. It's also easier to keep clean commits (no trailing comma issue). That said, I think http://json5.org/ http://json5.org/ is a decent middle term.