TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

YAML is not a superset of JSON

59 点作者 Smaug1238 个月前

13 条评论

DougBTX8 个月前
This article claims that 1e2 is interpreted as a string, while this other article on the front page[0] claims that 556474e378 is interpreted as a number. What&#x27;s correct?<p>The YAML &quot;Scalars&quot; section[1] says:<p>&gt; A few examples also use the int, float and null types from the JSON schema.<p>And includes these examples:<p><pre><code> canonical: 1.23015e+3 exponential: 12.3015e+02 </code></pre> So, is the &quot;+&quot; required here or not? Is a YAML parser buggy if it doesn&#x27;t parse all JSON numbers as numbers?<p>Edit: Ah, further on, it says:<p><pre><code> Canonical Form Either 0, .inf, -.inf, .nan or scientific notation matching the regular expression -? [1-9] ( \. [0-9]* [1-9] )? ( e [-+] [1-9] [0-9]* )? </code></pre> The example 1e2 clearly matches this regex, so his YAML parser is broken.<p>Edit edit:<p>In YAML 1.1, there were separate definitions of float[2] and int[3] types, where only floats support &quot;scientific&quot; notation, and must have a &quot;.&quot;, unlike JSON.<p>So this article is talking about YAML 1.1, while the other article is talking about YAML 1.2.<p>[0] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41498264">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41498264</a><p>[1] <a href="https:&#x2F;&#x2F;yaml.org&#x2F;spec&#x2F;1.2.2&#x2F;#23-scalars" rel="nofollow">https:&#x2F;&#x2F;yaml.org&#x2F;spec&#x2F;1.2.2&#x2F;#23-scalars</a><p>[2] <a href="https:&#x2F;&#x2F;yaml.org&#x2F;type&#x2F;float.html" rel="nofollow">https:&#x2F;&#x2F;yaml.org&#x2F;type&#x2F;float.html</a><p>[3] <a href="https:&#x2F;&#x2F;yaml.org&#x2F;type&#x2F;int.html" rel="nofollow">https:&#x2F;&#x2F;yaml.org&#x2F;type&#x2F;int.html</a>
评论 #41508999 未加载
评论 #41509025 未加载
评论 #41509192 未加载
评论 #41508995 未加载
wolframhempel8 个月前
I feel there&#x27;s a place for YAML and JSON and that they are quite different:<p>- YAML is for files written or edited by humans - e.g. configuration files for servers with lots of comments and explanations, but generally quite simple key value pairs or basic data structures<p>- JSON is for files written and consumed by machines. It allows for complex, nested data structures and types, but requires technical knowledge to use.<p>The problem arises once you start confusing these usecases. I&#x27;d argue that once you start writing `&#x27;{&quot;a&quot;: 1e2}&#x27;` in YAML you&#x27;re quite far outside of its ideal use. I appreciate that feature creep might lead to overly complex configuration files (I remember editing XML config that allowed you to specify for-loops in my earlier days), but really, at a certain point it might be worth taking a step back and reflecting if you&#x27;re still using the right tool for the right job.
评论 #41509224 未加载
评论 #41509072 未加载
评论 #41509486 未加载
评论 #41509171 未加载
zquestz8 个月前
I am confused, when was YAML ever considered a superset of JSON?<p>These are completely different serialization formats.
评论 #41508973 未加载
评论 #41508966 未加载
评论 #41508994 未加载
评论 #41508979 未加载
评论 #41509087 未加载
评论 #41508993 未加载
valenterry8 个月前
Please just drop YAML. Stop using it. Especially if you are devops and building a new CICD solution or configuration.<p>If you <i>must</i> use some kind of configuration language, at least use Dhall or something more sane. Thank you in advance!
endycm8 个月前
Author has no clue, but I don&#x27;t blame him.<p>There are - similar to the JSON insanity - multiple YAML standards.<p>YAML 1.1 and 1.2+ are the important ones, as the &quot;superset&quot; argument is only valid since 1.2.<p>HOWEVER PyYAML is a YAML 1.1 parser: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;PyYAML&#x2F;#description" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;PyYAML&#x2F;#description</a><p>This also can be responsible for many security problems, as ppl will assume things about JSON and YAML, but don&#x27;t worry about which of the 8 different JSON standards &#x2F; YAML implementations they use.
评论 #41509147 未加载
评论 #41509048 未加载
xelxebar8 个月前
Ouch. That tab error is a bug in libyaml, the YAML loader used by PyYAML. It&#x27;s still stuck on YAML 1.1, but the spec explicitly allows tabs as whitespace, though they don&#x27;t count as indentation semantics.[0]<p>The same is true in YAML 1.2, so it&#x27;s not just a legacy thing, either.<p>[0]:<a href="https:&#x2F;&#x2F;yaml.org&#x2F;spec&#x2F;1.1&#x2F;#id893482" rel="nofollow">https:&#x2F;&#x2F;yaml.org&#x2F;spec&#x2F;1.1&#x2F;#id893482</a>
评论 #41510170 未加载
jayceedenton8 个月前
This seems pedantic, but I suppose anyone using the term &#x27;superset&#x27; is inviting the pedantry.<p>For almost all intents and purposes, if you are asked to create a YAML file then you can choose JSON as your syntax instead, because your file will be understood by the YAML parser. The benefit being that JSON has far fewer quirks and edge cases.<p>It&#x27;s comical that when people get confused with YAML (which is often) they convert their YAML snippet to JSON to see what&#x27;s really going on. YAML is horrible for humans to write. Let&#x27;s just use JSON, the sane syntax, instead. A few extra parents and quotes is really no big deal, and it&#x27;s far easier to read unambiguously.
评论 #41509194 未加载
评论 #41509215 未加载
kkfx8 个月前
They are both ideas to makes XML easier, more manageable, as XML was for SGML, and well... They are damn failures. Modern YAML and JSON monsters clearly prove this.<p>If we want human readability we should accept not being language agnostic or simply direct use a programming language for data as well (lisp teach), if we want a textual language agnostic data exchange format than we should ignore human readability and maybe stick with XML.
masfoobar8 个月前
I have never been fond of yaml. Guess it really depends on what you have been accustomed to. Then again, if that were true I would be defending xml over json.<p>I guess there is a place for all... but I do wish s-expressions got more love. :-)
nvader8 个月前
YAML is the Papyrus of serialization formats.<p>Great for cutesy human-readable applications but nothing workhorse. Just as I&#x27;d happily use Papyrus for invitations to a neighborhood barbecue but not a resume.
widforss8 个月前
This should 100 % be named YAML is almost a superset of JSON. TIL.
msoad8 个月前
`&#x27;{&quot;a&quot;: 1e2}&#x27;` is YAML not JSON. What a weird argument.
评论 #41509009 未加载
trueismywork8 个月前
Technically right but useless. When people talk about superset, they rarely are considering code formatting or parsing.
评论 #41509151 未加载