18 ms·
I accidentally used YAML.parse instead of JSON.parse and it worked
- Ygg2 5y agoYes. Yaml is super set of JSON. It's not a feature, it's a bug. Regardless of what Yaml group says.
- kevincox 5y agoIt is very convenient when you need to generate YAML via text template which unfortunately appears to be something that our industry has decided is reasonable. You can do {{ someval | toJson }} and have reliable escaping. Way better than "{{ someval }}" or {{ someval | toJson | indent 13 }}
- gavinray 5y ago"In which the author discovers that YAML is a spec-compliant superset of JSON" ;^)
- mastazi 5y agoexcept it seems it's not really the case? https://news.ycombinator.com/item?id=30052685 https://news.ycombinator.com/item?id=30052685
- mdaniel 5y agoDid you try the cited example? Because I did, and it parsed as expected I do believe there are likely some incompatibility bombs hiding in either the monster specification, or undoubtedly in the various implementations, but it was not my experience that one is the one to bring to yaml's court case
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- jerf 5y agoYAML was intended to be a superset, but it isn't quite, which is about the worst case scenario. See https://metacpan.org/pod/JSON::XS#JSON-and-YAML https://metacpan.org/pod/JSON::XS#JSON-and-YAML , for instance. (I am an absolutist on this matter. To be a superset, all, that's A L L valid JSON strings must also be valid YAML to be a superset. A single failure makes it not a superset. At scale, any difference will eventually occur, which is why even small deviations matter.)
- remram 5y agoFor example, this valid JSON doesn't parse as YAML: { "list": [ {}, {} ] } (tested on Python) edit: whitespace didn't quite make it through HN, here: json.loads('{\n "list": [\n {},\n\t{}\n ]\n}') yaml.load ('{\n "list": [\n {},\n\t{}\n ]\n}')
- dheera 5y agotry: try: import orjson as json except: try: import rapidjson as json except: try: import fast_json as json except: import json foo = json.loads(string) except: try: import yaml except: # try harder import os try: assert(os.system("pip3 install yaml") == 0) except: # try even harder try: assert(os.system("sudo apt install python3-pip && pip3 install yaml") == 0) except: assert(os.system("sudo yum install python3-pip && pip3 install yaml") == 0) import yaml try: foo = yaml.loads(string) except: try: ....
- tomjakubowski 5y agoGreat idea. pip install --user yaml increases the chances it will work
- imoverclocked 5y ago
- bin_bash 5y agoFun fact: Heroku's app.json actually uses a YAML parser so even though it isn't documented you could use YAML with it. (At least this was the case years ago, it's possible it may have changed)
- tommoor 5y agoJSON?
- eyelidlessness 5y agoThere’s an ambiguous question mark here?
- ramraj07 5y agoThis is at odds with the top comment here suggesting there are edge case bugs. Assuming validly heroku wouldn’t use something buggy like that either the top comment is wrong or heroku uses two different parsers after inferring type.
- bin_bash 5y agothe top comment is wrong, YAML 1.2+ is a strict superset of JSON
- CameronNemo 5y agoMany parsers either default to YAML pre-1.2 or do not even expose a YAML 1.2 option. PyYAML has no 1.2 option, for example. So unless Ansible is using something other than PyYAML... Relevant (open) PR: https://github.com/yaml/pyyaml/pull/555 https://github.com/yaml/pyyaml/pull/555
- IggleSniggle 5y agoUnfortunately, it claims to be, but is not an actual strict superset.
- lelandbatey 5y ago
- LudwigNagasena 5y agoAre people not even reading about what they are using? Always read documentation or you will get burned by something completely innocuous. For example, that’s how you get Norway missing in your config file with YAML: NI: Nicaragua NL: Netherlands NO: Norway Oops, “NO” evaluates to false like 10 other reserve words.
- whatshisface 5y agoAmazing that people use YAML if it does that.
- fennecfoxen 5y agoThis is why I default to TOML for these sorts of lists of things.
- deleted 5y ago[deleted]
- viraptor 5y agoYou just learn about the edge cases. This applies to everything. There's a number of languages where an empty list/array is truthy and a number where it's falsey. Learn the tool, do some defensive programming (always quote the strings) and you'll be fine. (This issue was recognised and since yaml 1.2 (2009) the spec says "no" is a string, packages like https://yaml.readthedocs.io/ https://yaml.readthedocs.io/ have migrated a while ago)
- Lexarius 5y agoThat's an old YAML 1.1 behavior. It was removed in 1.2 (in 2009), though some implementations (looking at you, pyyaml) are still on 1.1.
- account42 5y agoSo YAML is fine with breaking compatibility in minor version bumps?
- k_sze 5y agoI have a love-hate relationship with YAML. Hate: - human-wise ambiguity of its syntax (If I understand correctly, you "can" indent array items, but you don't have to. And than one guys says "OK, I'm gonna indent", and another guy says "Nah. I'm not gonna indent") - still no support for datetime as a first class citizen - strings usually don't need quotes, until they do (I prefer to always quote) Note that two of the above points are about allowing inconsistent styles, which is a thing I hate. Love: - it supports comments whereas JSON does not. If the IETF ever officially updated JSON to support C-style inline (and maybe block) comments, I would absolutely ditch YAML.
- thayne 5y agoSo use any of a dozen or so other configuration formats that have comments but don't have all the problems YAML does. TOML is probably the most popular of those right now.
- deleted 5y ago[deleted]
- k_sze 5y agoTOML is good for config, but not for data exchange though. (Why would I need comments in a data exchange format? Comments are useful when you want to annotate some sample data for other developers who will consume or generate that data.) Also, OpenAPI specs (also known colloquially as Swagger) can only be written in JSON or YAML.
- makeitdouble 5y agoYour requirements seem to be getting pretty close to XML territory. To note, JSON specifically doesn’t have comments to close the door to annotations and other kind of meta use.
- thayne 5y agoAgreed, so use JSON for data exchange and TOML for configuration. YAML isn't all that great for data exchange either. In the cases where you have a tool that require json or yaml, you could use something like cue, dhall, or jsonnet, and convert it into json (or yaml). Unfortunately, that's a little tricky when your build cinfiguration itself has to be in yaml, as is the case for github actions, travis-ci, etc.
- cirrus3 5y agohttps://noyaml.com https://noyaml.com
- systemvoltage 5y agoHow about no emojis? Am I the only one who finds these abominations annoying in code/docs? Slack chat? Fine. npm logs with emojis? No thanks.
- duxup 5y agoMore emojis! (Ok not really)
- eyelidlessness 5y agoYou’re welcome to that opinion but you’re just going to age restrict yourself and have artificially limited impact informing others ¯\_(ツ)_/¯
- eyelidlessness 5y agoOkay, since this felt like common knowledge and apparently is also an unpopular opinion: emojis can and often do improve accessibility of documentation. Like any other symbolic reference in text, their use can be defined in a key and they can be used to concisely document a support matrix, or signal complexity levels of deeper links, or… even just thematically identify content in a friendly and inviting way.
- yjftsjthsd-h 5y agoDo they? Even if you use them perfectly consistently, people need to know what they mean. For some really common ones that might be fine (green check mark on CI probably means the build ran successfully), but the moment anyone gets confused or doesn't recognize a symbol I feel like accessibility drops off a cliff.
- 5y ago
- eyelidlessness 5y agoFinally YAML does something it’s expected to do if you acquire expectations from YAML!
- deleted 5y ago[deleted]
- kuon 5y agoI have no hate for YAML, but I think this is the "human readable" format with the most gotchas you might ever encounter. Every time I use YAML, I got bitten by some edge case. For this reason, I wouldn't count of JSON compatibility, except if the implementation also passes a comprehensive set of JSON tests (which the few I used in the past did not).
- matsemann 5y agoEven after writing yaml for years, I can never get the indentation, when to use a dash or not and other things right without an editor knowing the spec of the yaml file I'm trying to write. It's bonkers.
- aidenn0 5y agoWhile we are complaining about YAML, I'd like them to specify a canonical output form for strings...
- nsonha 5y ago
- mahoro 5y agofor fun: I accidentally compiled a C program with g++ and it worked! continue?
- mirekrusin 5y agoAccidentally read xml with html parser and it worked!
- deleted 5y ago[deleted]
- jwilk 5y agoBeware of security implications of using a YAML parser: https://docs.ruby-lang.org/en/3.0/YAML.html#module-YAML-label-Security https://docs.ruby-lang.org/en/3.0/YAML.html#module-YAML-labe... > Do not use YAML to load untrusted data. Doing so is unsafe and could allow malicious input to execute arbitrary code inside your application.
- jokoon 5y agoI have to admit I created my own YAML-like parser (meaning, syntax based on indentation). My parser just outputs things to json Just like python, it's just more readable. Readability is so important for a language, it's more important than feature or correctness.
- diogenesjunior 5y agoSlightly off topic, but does anybody know what lang the author is using? I think ruby?
- rohitpaulk 5y agoYep, that's Ruby.
- diogenesjunior 5y agoThank you
- deleted 5y ago[deleted]
- omnicognate 5y ago"Autopilot took over" - figurative autopilot or Github Autopilot?
- ingy 5y agoI'm one of the authors of the YAML specification. https://yaml.org/spec/1.2.2/ https://yaml.org/spec/1.2.2/ To date we honestly have not identified a case where where valid JSON is not valid YAML 1.2. If anyone can point out a case where this is true, please file an issue here: https://github.com/yaml/yaml-spec/issues/ https://github.com/yaml/yaml-spec/issues/