Skip to content

How to avoid quotes for Integers, Boolean values in JSON output #1478

Answered by mikefarah
ajit4sbi asked this question in Q&A
Discussion options

You must be logged in to vote

The XML parser assumes everything is a string - you can do this to attempt to parse all the scalar values into their types:

yq -p=xml ' (.. | select(tag == "!!str")) |= from_yaml' sample.xml

This selects all the string values and runs them through 'from_yaml'. That function will convert to numbers/floats/booleans if it can, otherwise it will leave the string value as is.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mikefarah
Comment options

Answer selected by ajit4sbi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants