kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.57k stars 82 forks source link

Empty YAML file produces an empty JSON file #97

Closed lpellegr closed 4 years ago

lpellegr commented 4 years ago

While using yq (version 2.10.1) to convert several files, I noticed that an empty YAML file produces an empty JSON file while I was expecting {} as JSON.

The command used is the following:

$ yq . empty.yaml

I am not sure it can be considered as a bug since the JSON grammar allows an empty object or array as root. As a consequence, I was wondering if there an equivalent to an empty object ({}) in YAML so that once passed to yq, the output is {}?

The command echo "{}" | yq -y . returns {}, which does not seem to make sense.

kislyuk commented 4 years ago

This behavior is correct, and your expectation to get an empty object is not correct. An empty YAML document gets loaded as a null scalar, which is equivalent to JSON. You can use the object literal {} to get an empty object in YAML. Why does the command output not make sense to you?

lpellegr commented 4 years ago

Most probably my lack of knowledge about YAML. Thanks for the clarification.