News for hackers. Stuff that matters.
Re:I accidentally used YAML.parse instead of JSON.parse and ... by hoherd on Monday January 24, 2022 @12:17AM (#30053975)
With leading tabs it does not work.

  $ sed 's/\t/--->/g' break-yaml.json
  --->{
  --->--->"list": [
  --->--->--->{},
  --->--->--->{}
  --->--->]
  --->}
  $ jq -c . break-yaml.json
  {"list":[{},{}]}
  $ yaml-to-json.py break-yaml.json
  ERROR: break-yaml.json could not be parsed
  while scanning for the next token
  found character '\t' that cannot start any token
    in "break-yaml.json", line 1, column 1
  $ sed 's/\t/    /g' break-yaml.json | yaml-to-json.py
  {"list": [{}, {}]}
Re:I accidentally used YAML.parse instead of JSON.parse and ... by ingy on Monday January 24, 2022 @02:23PM (#30062570)
This is completely valid YAML.

YAML does not allow tabs in indentation, but the tabs in your example are not indentation according to the YAML spec productions.

You can see it clearly here against many YAML parsers: https://play.yaml.io/main/parser?input=CXsKCQkibGlzdCI6IFsKC...

As tinita points out, sadly PyYAML and libyaml implement this wrong.

See https://matrix.yaml.info/

Re:I accidentally used YAML.parse instead of JSON.parse and ... by tinita on Monday January 24, 2022 @01:24PM (#30061685)
That's because PyYAML doesn't implement the spec correctly.
Re:I accidentally used YAML.parse instead of JSON.parse and ... by MrPatan on Monday January 24, 2022 @03:31AM (#30054868)
Tabs are not valid JSON
Re:I accidentally used YAML.parse instead of JSON.parse and ... by zimpenfish on Monday January 24, 2022 @03:44AM (#30054952)
Do you have a link for that?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... says:

> Insignificant whitespace may be present anywhere except within a JSONNumber [forbidden] or JSONString [interpreted as part of the string]

And specifically lists tab as whitespace:

> The tab character (U+0009), carriage return (U+000D), line feed (U+000A), and space (U+0020) characters are the only valid whitespace characters.

More specifically, expanding https://datatracker.ietf.org/doc/html/rfc8259#section-2 gives an array as (roughly)

> ws %x5B ws value (ws %x2C ws value)* ws %x5D ws

Where `ws` explicitly includes `%x09`. Which seems to cover this case?

Re:I accidentally used YAML.parse instead of JSON.parse and ... by tonyg on Monday January 24, 2022 @04:23AM (#30055198)
Per RFC 8259:

      ws = *(
              %x20 /              ; Space
              %x09 /              ; Horizontal tab
              %x0A /              ; Line feed or New line
              %x0D )              ; Carriage return
Re:I accidentally used YAML.parse instead of JSON.parse and ... by Someone on Monday January 24, 2022 @04:15AM (#30055129)
The grammar in https://www.json.org/json-en.html disagrees. It has

  json
    element

  element
    ws value ws

  ws
    ‘0009’ ws