[HN Gopher] JSON is not a YAML subset (2022)
       ___________________________________________________________________
        
       JSON is not a YAML subset (2022)
        
       Author : AndrewDucker
       Score  : 16 points
       Date   : 2025-08-01 21:06 UTC (1 hours ago)
        
 (HTM) web link (john-millikin.com)
 (TXT) w3m dump (john-millikin.com)
        
       | sshine wrote:
       | I wonder how widespread YAML 1.1 is.
       | 
       | If you assume that YAML 1.2 is the default, you don't need that
       | nasty %YAML header.
       | 
       | This doesn't translate to arbitrary, open environments, but you
       | can make that choice in closed environments.
       | 
       | While JSON numbers are grammatically simple, they're almost
       | always distinct from how you'd implement numbers in any language
       | that has JSON parsers, syntactically, exactness and precision-
       | wise.
       | 
       | So while YAML is a lot more complex, you always need to limit
       | yourself from what kinds of numbers you actually try to express
       | in JSON. This is especially true for scientific numbers, big
       | numbers, and numbers exact down to many digits.
        
         | jorams wrote:
         | > If you assume that YAML 1.2 is the default, you don't need
         | that nasty %YAML header.
         | 
         | Indeed the YAML 1.2 spec says a document without a YAML
         | directive should be assumed to be 1.2[1]:
         | 
         | > A version 1.2 YAML processor must accept documents with an
         | explicit "%YAML 1.2" directive, as well as documents lacking a
         | "YAML" directive. Such documents are assumed to conform to the
         | 1.2 version specification.
         | 
         | It's only the YAML 1.2 spec that says it's a superset of JSON.
         | The YAML authors weren't aware of JSON when publishing version
         | 1.1[2]:
         | 
         | > The YAML 1.1 specification was published in 2005. Around this
         | time, the developers became aware of JSON. By sheer
         | coincidence, JSON was almost a complete subset of YAML (both
         | syntactically and semantically).
         | 
         | > In 2006, Kyrylo Simonov produced PyYAML and LibYAML. A lot of
         | the YAML frameworks in various programming languages are built
         | over LibYAML and many others have looked to PyYAML as a solid
         | reference for their implementations.
         | 
         | > The YAML 1.2 specification was published in 2009. Its primary
         | focus was making YAML a strict superset of JSON. It also
         | removed many of the problematic implicit typing
         | recommendations.
         | 
         | The middle paragraph there is the reason this is a problem
         | people keep running into: Most implementations are based on
         | LibYAML, which is an implementation of YAML 1.1 that does not
         | really support 1.2[3]. Indeed the last example from the post
         | doesn't actually work for me on Ruby 3.4.4 with LibYAML 0.2.5.
         | It produces the exact same output as the one before it.
         | 
         | [1]: https://yaml.org/spec/1.2.2/#681-yaml-directives
         | 
         | [2]: https://yaml.org/spec/1.2.2/#12-yaml-history
         | 
         | [3]: https://github.com/yaml/libyaml/issues/20
        
       | pavel_lishin wrote:
       | > _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?
        
       ___________________________________________________________________
       (page generated 2025-08-01 23:00 UTC)