Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json output converts numbers to strings #119

Open
dmivankov opened this issue Apr 28, 2021 · 1 comment
Open

json output converts numbers to strings #119

dmivankov opened this issue Apr 28, 2021 · 1 comment

Comments

@dmivankov
Copy link

# roundtrip works
$ echo "a: 1e+9" | yq -Y .
a: 1e+9

# json output quotes the number
$ echo "a: 1e+9" | yq  .
{
  "a": "1e+9"
}

# json output can't be used for roundtrip
$ echo "a: 1e+9" | yq  . | yq -Y .
a: "1e+9"

# same output with string in input as with number
$ echo "a: \"1e+9\"" | yq  . 
{
  "a": "1e+9"
}

"Another yq" (https://github.com/mikefarah/yq) outputs numbers as json numbers

$ echo "a: 1e+9" | yq eval . -j - 
{
  "a": 1000000000
}

Would be nice to be able to do the roundtrip with intermediate json format too, or in other words make json conversion not lossy.

@kislyuk
Copy link
Owner

kislyuk commented Apr 28, 2021

This is a problem in the underlying YAML parser, PyYAML: yaml/pyyaml#173. It seems the workaround is to patch the YAML parser's configuration with better regular expressions for floating point: https://stackoverflow.com/a/30462009/1380386

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

No branches or pull requests

2 participants