question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Apostrophes are dropped when converting back to YAML

See original GitHub issue

Hello,

First of all, thank you for the great tool that is yq.

I would like to report a problem I noticed in version 3.0.2, well values of type string whose value is yes or no, when converted back to YAML have apostrophes dropped, which will cause the YAML parser to convert such values to type boolean. See the following examples.

My environment:

$ jq --version
jq-master-v20210212-7320-g4be84a0f82
$ yq --version
yq 3.0.2
$ python3 --version
Python 3.9.5
$ cat /etc/alpine-release 
3.14.0

Example file example.yaml:

---
graphana_dashboard: 'yes'

Actual command result:

$ yq --yaml-output '.' example.yaml 
graphana_dashboard: yes

Expected result of the command:

$ yq --yaml-output '.' example.yaml 
grafana_dashboard: 'yes'

For the example in version 2.14.0, which I have used so far, the result of the command is as expected. I also checked what the document looks like in JSON format, after conversion by yq 3.0.2, well it is as expected, which would mean that the problem occurs when converting from JSON to YAML again.

$ yq '.' example.yaml 
{
  "grafana_dashboard": "yes"
}

Regards Piotr Minkina

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kislyukcommented, Jul 22, 2022

Thanks for the feedback. I’ve been thinking about this and I’m going to release an update to v3 which will use yaml 1.2 as the input grammar, but yaml 1.1 as the output grammar by default. This will preserve the quotes in the example that you gave.

Please understand that this is a tricky backwards compatibility situation. If you take the github actions yaml for example, it uses the bare on: key frequently, implying the 1.2 grammar. Any yq invocations on that yaml should keep the output formatting as close to the original as possible, but I agree with you that the safest/most backwards compatible output is to quote the ambiguous values - resulting in "on": and other quoting that may appear inconsistent.

0reactions
kislyukcommented, Jul 24, 2022

Released in v3.1.0, please test.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: Apostrophes are dropped when converting back to YAML ...
Bug : Apostrophes are dropped when converting back to YAML. ... apostrophes dropped, which will cause the YAML parser to convert such values...
Read more >
toYaml removes all quotes and yaml types breaks · Issue #4262
Any issues related to how those values are parsed and passed back to the template engine would be a bug in the YAML...
Read more >
python - Having issues escaping single quote - Stack Overflow
What you are trying to do is use YAML single quotes scalar escaping mechanism in Python, and that would only work if you...
Read more >
YAML Ain't Markup Language (YAML™) revision 1.2.2
Chapter 3 describes the YAML information model and the processes for converting from and to this model and the YAML text format.
Read more >
YAML Syntax — Ansible Documentation
This page provides a basic overview of correct YAML syntax, which is how Ansible playbooks (our configuration management language) are expressed. We use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found