# YAML Test Matrix

--- &test-NKF9
  Title: Empty keys in block and flow mapping
  Tags: [ empty-key, mapping ]

YAML

---
key: value
: empty key
---
{
 key: value, : empty key
}
---
# empty key and value
:
---
# empty key and value
{ : }

Expected Events

+STR
+DOC ---
+MAP
=VAL :key
=VAL :value
=VAL :
=VAL :empty key
-MAP
-DOC
+DOC ---
+MAP {}
=VAL :key
=VAL :value
=VAL :
=VAL :empty key
-MAP
-DOC
+DOC ---
+MAP
=VAL :
=VAL :
-MAP
-DOC
+DOC ---
+MAP {}
=VAL :
=VAL :
-MAP
-DOC
-STR

Expected JSON



c-libfyaml-event

 ok

cpp-rapidyaml-event

 ok

cpp-yamlcpp-event

 ok

dotnet-yamldotnet-event

 ok

hs-hsyaml-event

 ok

js-yaml-event

 ok

nim-nimyaml-event

 ok

perl-pp-event

 ok

perl-refparser-event

 ok

py-ruamel-event

 ok

rust-yamlrust-event

 ok

perl-syck-perl

 error
Syck parser (line 3, column 1): syntax error at /perl5/lib/perl5/x86_64-linux-thread-multi/YAML/Syck.pm line 60, <> line 1.

perl-yaml-perl

 error
YAML Error: Expected separator '---'
   Code: YAML_PARSE_ERR_NO_SEPARATOR
   Line: 5
   Document: 3
 at /perl5/lib/perl5/YAML/Loader.pm line 88.

c-libfyaml-json

 na
{
  "key": "value",
  "": "empty key"
}
{
  "key": "value",
  "": "empty key"
}
{
  "": null
}
{
  "": null
}

dotnet-yamldotnet-json

 na
Unhandled exception. YamlDotNet.Core.YamlException: (Line: 2, Col: 1, Idx: 4) - (Line: 2, Col: 1, Idx: 4): Exception during deserialization
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.set_Item(Object key, Object value)
   at YamlDotNet.Serialization.NodeDeserializers.DictionaryNodeDeserializer.DeserializeHelper(Type tKey, Type tValue, IParser parser, Func`3 nestedObjectDeserializer, IDictionary result)
   at YamlDotNet.Serialization.NodeDeserializers.DictionaryNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   --- End of inner exception stack trace ---
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.ValueDeserializers.AliasValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.Deserializer.Deserialize(IParser parser, Type type)
   at YamlDotNet.Serialization.Deserializer.Deserialize(TextReader input, Type type)
   at YamlDotNet.Serialization.Deserializer.Deserialize(TextReader input)
   at Program.Main(String[] commandLineArguments)
Aborted (core dumped)

go-yaml-json

 na
yaml: line 2: did not find expected key

hs-hsyaml-json

 na
{"":"empty key","key":"value"}
{"":"empty key","key":"value"}
{"":null}
{"":null}

hs-reference-yeast

 na
Line  Col Char Byte Token|Content
   1    0    0    0 +DOC |
   1    0    0    0 =HEAD|---
   1    3    3    3 +NODE|
   1    3    3    3 =EOL |\x0a
   2    0    4    4 +MAP |
   2    0    4    4 +PAIR|
   2    0    4    4 +NODE|
   2    0    4    4 +VAL |
   2    0    4    4 =TEXT|key
   2    3    7    7 -VAL |
   2    3    7    7 -NODE|
   2    3    7    7 =SYNX|:
   2    4    8    8 =WSPC|.
   2    5    9    9 +NODE|
   2    5    9    9 +VAL |
   2    5    9    9 =TEXT|value
   2   10   14   14 -VAL |
   2   10   14   14 -NODE|
   2   10   14   14 =EOL |\x0a
   3    0   15   15 -PAIR|
   3    0   15   15 +PAIR|
   3    0   15   15 +NODE|
   3    0   15   15 +VAL |
   3    0   15   15 -VAL |
   3    0   15   15 -NODE|
   3    0   15   15 =SYNX|:
   3    1   16   16 =WSPC|.
   3    2   17   17 +NODE|
   3    2   17   17 +VAL |
   3    2   17   17 =TEXT|empty.key
   3   11   26   26 -VAL |
   3   11   26   26 -NODE|
   3   11   26   26 =EOL |\x0a
   4    0   27   27 -PAIR|
   4    0   27   27 -MAP |
   4    0   27   27 -NODE|
   4    0   27   27 -DOC |
   4    0   27   27 +DOC |
   4    0   27   27 =HEAD|---
   4    3   30   30 =EOL |\x0a
   5    0   31   31 +NODE|
   5    0   31   31 +MAP |
   5    0   31   31 =SYNX|{
   5    1   32   32 =EOL |\x0a
   6    0   33   33 =WSPC|.
   6    1   34   34 +PAIR|
   6    1   34   34 +NODE|
   6    1   34   34 +VAL |
   6    1   34   34 =TEXT|key
   6    4   37   37 -VAL |
   6    4   37   37 -NODE|
   6    4   37   37 =SYNX|:
   6    5   38   38 =WSPC|.
   6    6   39   39 +NODE|
   6    6   39   39 +VAL |
   6    6   39   39 =TEXT|value
   6   11   44   44 -VAL |
   6   11   44   44 -NODE|
   6   11   44   44 -PAIR|
   6   11   44   44 =SYNX|,
   6   12   45   45 =WSPC|.
   6   13   46   46 +PAIR|
   6   13   46   46 +NODE|
   6   13   46   46 +VAL |
   6   13   46   46 -VAL |
   6   13   46   46 -NODE|
   6   13   46   46 =SYNX|:
   6   14   47   47 =WSPC|.
   6   15   48   48 +NODE|
   6   15   48   48 +VAL |
   6   15   48   48 =TEXT|empty.key
   6   24   57   57 -VAL |
   6   24   57   57 -NODE|
   6   24   57   57 -PAIR|
   6   24   57   57 =EOL |\x0a
   7    0   58   58 =SYNX|}
   7    1   59   59 -MAP |
   7    1   59   59 -NODE|
   7    1   59   59 =EOL |\x0a
   8    0   60   60 -DOC |
   8    0   60   60 +DOC |
   8    0   60   60 =HEAD|---
   8    3   63   63 +NODE|
   8    3   63   63 =EOL |\x0a
   9    0   64   64 +COMM|
   9    0   64   64 =SYNX|#
   9    1   65   65 =META|.empty.key.and.value
   9   21   85   85 -COMM|
   9   21   85   85 =EOL |\x0a
  10    0   86   86 +MAP |
  10    0   86   86 +PAIR|
  10    0   86   86 +NODE|
  10    0   86   86 +VAL |
  10    0   86   86 -VAL |
  10    0   86   86 -NODE|
  10    0   86   86 =SYNX|:
  10    1   87   87 +NODE|
  10    1   87   87 +VAL |
  10    1   87   87 -VAL |
  10    1   87   87 -NODE|
  10    1   87   87 =EOL |\x0a
  11    0   88   88 -PAIR|
  11    0   88   88 -MAP |
  11    0   88   88 -NODE|
  11    0   88   88 -DOC |
  11    0   88   88 +DOC |
  11    0   88   88 =HEAD|---
  11    3   91   91 =EOL |\x0a
  12    0   92   92 +COMM|
  12    0   92   92 =SYNX|#
  12    1   93   93 =META|.empty.key.and.value
  12   21  113  113 -COMM|
  12   21  113  113 =EOL |\x0a
  13    0  114  114 +NODE|
  13    0  114  114 +MAP |
  13    0  114  114 =SYNX|{
  13    1  115  115 =WSPC|.
  13    2  116  116 +PAIR|
  13    2  116  116 +NODE|
  13    2  116  116 +VAL |
  13    2  116  116 -VAL |
  13    2  116  116 -NODE|
  13    2  116  116 =SYNX|:
  13    3  117  117 +NODE|
  13    3  117  117 +VAL |
  13    3  117  117 -VAL |
  13    3  117  117 -NODE|
  13    3  117  117 -PAIR|
  13    3  117  117 =WSPC|.
  13    4  118  118 =SYNX|}
  13    5  119  119 -MAP |
  13    5  119  119 -NODE|
  13    5  119  119 =EOL |\x0a
  14    0  120  120 -DOC |

js-jsyaml-json

 na
/node/node_modules/js-yaml/lib/loader.js:187
  throw generateError(state, message);
  ^
YAMLException: incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line (3:1)

 1 | ---
 2 | key: value
 3 | : empty key
-----^
 4 | ---
 5 | {
    at generateError (/node/node_modules/js-yaml/lib/loader.js:183:10)
    at throwError (/node/node_modules/js-yaml/lib/loader.js:187:9)
    at readBlockMapping (/node/node_modules/js-yaml/lib/loader.js:1090:9)
    at composeNode (/node/node_modules/js-yaml/lib/loader.js:1441:12)
    at readDocument (/node/node_modules/js-yaml/lib/loader.js:1625:3)
    at loadDocuments (/node/node_modules/js-yaml/lib/loader.js:1688:5)
    at Object.loadAll (/node/node_modules/js-yaml/lib/loader.js:1701:19)
    at Object.<anonymous> (/yaml/bin/js-jsyaml-json:7:13)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10) {
  reason: 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line',
  mark: {
    name: null,
    buffer: '---\n' +
      'key: value\n' +
      ': empty key\n' +
      '---\n' +
      '{\n' +
      ' key: value, : empty key\n' +
      '}\n' +
      '---\n' +
      '# empty key and value\n' +
      ':\n' +
      '---\n' +
      '# empty key and value\n' +
      '{ : }\n',
    position: 15,
    line: 2,
    column: 0,
    snippet: ' 1 | ---\n 2 | key: value\n 3 | : empty key\n-----^\n 4 | ---\n 5 | {'
  }
}

Node.js v20.13.1

js-yaml-json

 na
{
  "key": "value",
  "": "empty key"
}
{
  "key": "value",
  "": "empty key"
}
{
  "": null
}
{
  "": null
}

lua-lyaml-json

 na
luajit: 2:6: did not find expected key
stack traceback:
	[C]: in function 'error'
	/usr/local/share/lua/5.1/lyaml/init.lua:306: in function 'error'
	/usr/local/share/lua/5.1/lyaml/init.lua:325: in function 'parse'
	/usr/local/share/lua/5.1/lyaml/init.lua:443: in function 'load_node'
	/usr/local/share/lua/5.1/lyaml/init.lua:340: in function 'load_node'
	/usr/local/share/lua/5.1/lyaml/init.lua:497: in function 'load'
	/yaml/bin/lua-lyaml-json:6: in main chunk
	[C]: at 0x559f1d41ded0

perl-pp-json

 na
{
   "" : "empty key",
   "key" : "value"
}
{
   "" : "empty key",
   "key" : "value"
}
{
   "" : null
}
{
   "" : null
}

perl-pp-perl

 na
{
  '' => 'empty key',
  'key' => 'value'
}
{
  '' => 'empty key',
  'key' => 'value'
}
{
  '' => undef
}
{
  '' => undef
}

perl-pplibyaml-json

 na
YAML::PP::LibYAML Error: The problem:

    did not find expected key

was found at , line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

perl-syck-json

 na
Syck parser (line 3, column 1): syntax error at /perl5/lib/perl5/x86_64-linux-thread-multi/YAML/Syck.pm line 60, <> line 1.

perl-tiny-json

 na
YAML::Tiny failed to classify line ': empty key' at /yaml/bin/perl-tiny-json line 12.

perl-xs-json

 na
YAML::XS::Load Error: The problem:

    did not find expected key

was found at document: 1, line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

perl-yaml-json

 na
YAML Error: Expected separator '---'
   Code: YAML_PARSE_ERR_NO_SEPARATOR
   Line: 5
   Document: 3
 at /perl5/lib/perl5/YAML/Loader.pm line 88.

py-pyyaml-json

 na
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-json", line 19, in <module>
    for doc in yaml.load_all(sys.stdin.read(), Loader=yaml.FullLoader):
  File "/python/lib/python3.12/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
          ^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
                                   ^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
                         ^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/parser.py", line 438, in parse_block_mapping_key
    raise ParserError("while parsing a block mapping", self.marks[-1],
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
  in "<unicode string>", line 3, column 1:
    : empty key
    ^

py-ruamel-json

 na
Error json.dumps: <class 'TypeError'>
Traceback (most recent call last):
  File "/yaml/bin/py-ruamel-json", line 23, in <module>
    print(json.dumps(doc, sort_keys=True, skipkeys=True, indent=2))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 432, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.12/json/encoder.py", line 354, in _iterencode_dict
    items = sorted(dct.items())
            ^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'str'

py-ruamel-py

 na
{None: 'empty key', 'key': 'value'}
{None: 'empty key', 'key': 'value'}
{None: None}
{None: None}

ruby-psych-json

 na
/ruby/gems/psych/lib/psych.rb:458:in `parse': (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1 (Psych::SyntaxError)
	from /ruby/gems/psych/lib/psych.rb:458:in `parse_stream'
	from /ruby/gems/psych/lib/psych.rb:632:in `load_stream'
	from /yaml/bin/ruby-psych-json:6:in `<main>'

c-libyaml-event

 ni
+STR
+DOC ---
+MAP
=VAL :key
=VAL :value
Parse error: did not find expected key

perl-pplibyaml-perl

 ni
YAML::PP::LibYAML Error: The problem:

    did not find expected key

was found at , line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

perl-tiny-perl

 ni
YAML::Tiny failed to classify line ': empty key' at /yaml/bin/perl-tiny-perl line 15.

perl-xs-perl

 ni
YAML::XS::Load Error: The problem:

    did not find expected key

was found at document: 1, line: 3, column: 1
while parsing a block mapping at line: 2, column: 1

py-pyyaml-event

 ni
+STR
+DOC ---
+MAP
=VAL :key
=VAL :value
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-event", line 7, in <module>
    for event in yaml.parse(sys.stdin.read()):
  File "/python/lib/python3.12/site-packages/yaml/__init__.py", line 75, in parse
    while loader.check_event():
          ^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
                         ^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/parser.py", line 438, in parse_block_mapping_key
    raise ParserError("while parsing a block mapping", self.marks[-1],
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
  in "<unicode string>", line 3, column 1:
    : empty key
    ^

py-pyyaml-py

 ni
Traceback (most recent call last):
  File "/yaml/bin/py-pyyaml-py", line 36, in <module>
    for doc in yaml.load_all(sys.stdin.read(), Loader=yaml.FullLoader):
  File "/python/lib/python3.12/site-packages/yaml/__init__.py", line 130, in load_all
    yield loader.get_data()
          ^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
                                   ^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 27, in get_node
    return self.compose_document()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
                         ^^^^^^^^^^^^
  File "/python/lib/python3.12/site-packages/yaml/parser.py", line 438, in parse_block_mapping_key
    raise ParserError("while parsing a block mapping", self.marks[-1],
yaml.parser.ParserError: while parsing a block mapping
  in "<unicode string>", line 2, column 1:
    key: value
    ^
expected <block end>, but found ':'
  in "<unicode string>", line 3, column 1:
    : empty key
    ^