Skip to content

Improve handling of YAML document streams in std.parseYaml#862

Merged
johnbartholomew merged 1 commit intogoogle:masterfrom
johnbartholomew:yaml-doc-stream
Mar 8, 2026
Merged

Improve handling of YAML document streams in std.parseYaml#862
johnbartholomew merged 1 commit intogoogle:masterfrom
johnbartholomew:yaml-doc-stream

Conversation

@johnbartholomew
Copy link
Collaborator

This doesn't make them fully correct, in particular directives sections (e.g., "%YAML 1.2" directive before a document start marker) are not handled correctly, but they weren't handled correctly before, either.

It also doesn't recognise or try to do anything about document end markers (...).

This fix does allow scalar documents to be on the same line as the document start tag which is valid per examples in the YAML spec, see for example https://yaml.org/spec/1.2.1/#id2760844 (YAML 1.2.1 spec, section 2.3 Scalars)

It also matches the C++ jsonnet output for std.parseYaml("42\n---"), which is a stream of two documents, a scalar and then an empty document (where the empty document is interpreted as JSON null)

Fixes #861

This doesn't make them fully correct, in particular directives sections
(e.g., "%YAML 1.2" directive before a document start marker) are not
handled correctly, but they weren't handled correctly before, either.

It also doesn't recognise or try to do anything about document end
markers (`...`).

This fix does allow scalar documents to be on the same line as the
document start tag which is valid per examples in the YAML spec,
see for example https://yaml.org/spec/1.2.1/#id2760844
(YAML 1.2.1 spec, section 2.3 Scalars)

It also matches the C++ jsonnet output for std.parseYaml("42\n---"),
which is a stream of two documents, a scalar and then an empty document
(where the empty document is interpreted as JSON null)
@johnbartholomew johnbartholomew merged commit 4e09527 into google:master Mar 8, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ Jsonnet and Go Jsonnet have different YAML stream parsing behaviour

1 participant