3 ms·
The 013 to 11 issue is pretty obvious to any seasoned programmer. For example C, Ruby, and yes, also Javascript have the same "problem". Octal 13 is decimal 11
by bhaak 8y ago
The 013 to 11 issue is pretty obvious to any seasoned programmer. For example C, Ruby, and yes, also Javascript have the same "problem".
Octal 13 is decimal 11.
JSON should actually have the same issue. When I enter { 013: "11" } in the web console I get '{11: "11"}'. And YAML is backwards compatible to JSON.
That's IMO the actual problem of YAML. It could have supported a reasonable subset of JSON and not the whole nine yards.
- eridius 8y ago{ 013: "11" } isn't valid JSON. All object keys in JSON must be strings. And if you try to do that in value position, it's still not a problem because JSON never treats unquoted text as a string. Also JSON doesn't treat a 0 prefix on a number as special. There are no octal (or hex) literals in JSON. In fact, a JSON number literal cannot even start with 0 unless that's the only digit (before the period), e.g. 013 is not a valid numeric literal in JSON.
- matt_kantor 8y ago> JSON should actually have the same issue. When I enter { 013: "11" } in the web console I get '{11: "11"}'. JSON doesn't have this issue. `{ 013: "11" }` isn't valid according to the JSON spec for a couple reasons, the important one being that multi-digit numbers cannot start with zero[1]. Try this in the console: `JSON.parse('{"11": 013}')`. [1]: https://tools.ietf.org/html/rfc8259#section-6 https://tools.ietf.org/html/rfc8259#section-6
- aepiepaey 8y agoThe web console is not a JSON parser. To check if something parses as JSON in the web console you should use JSON.parse, e.g: JSON.parse('{ 013: "11" }') which should produce a syntax error (as already mentioned by siblings to this comment).
- bhaak 8y agoThanks. Yeah, I had mistakenly the believe that JSON is mostly a Javascript hash, not that 'JSON is valid Javascript' which means it's a subset of all possible Javascript hashes.