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.53k stars 81 forks source link

Read YAML and output TOML #180

Closed Karmaki closed 4 months ago

Karmaki commented 4 months ago

I was wondering if there is a way to take a YAML file as input, and output a TOML file? Since you are handling both formats, I thought it should be possible, but if it is, I do not find how.

Thanks in advance for your answer, and thanks for your nice tool.

kislyuk commented 4 months ago

Try this:

cat pyproject.toml | tomlq --yaml-output . > pyproject.yaml
cat pyproject.yaml | yq --toml-output . > pyproject.toml
Karmaki commented 4 months ago

Thank you very much for your answer.

I missed --toml-output option because it is not listed in my yq --help, and indeed, cat pyproject.yaml | yq . is OK, but with --toml-output, I get:

yq: Error running jq: _ConvertError: Invalid type <class 'NoneType'>.

My version is:

$ yq --version
yq 3.2.3

Maybe this is a new option?

kislyuk commented 4 months ago

The option is undocumented on purpose. It has been there for as long as TOML support has been there.

Can you paste the contents of your pyproject.toml?

kislyuk commented 4 months ago

Ah, I think I know what's happening there. You are trying to convert a YAML file with null values into TOML, which does not support them.

kislyuk commented 4 months ago

Filed #183

I'm going to close this issue since there is no bug that I can identify aside from that.

Karmaki commented 4 months ago

Sorry for the delay of my answer. Indeed, this was the problem. Thank you very much for your answer and for the new ticket.