-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Roundtrip to/from a property file breaks #1415
Comments
Yeah I see. I'll have to think about this - issue with a flag is that it wouldn't work if you had a mix of arrays and numeric keys. |
As a workaround, would it be ok to cast the numbered keys to strings (e.g. "400") before converting to props, and then parse them as numbers again after reading from props? |
You are right ... a general option for the whole decoding process is not sufficient. Leave the default behaviour as it is (treat numbers in key paths as array index).
or equivalent in the upper use case:
Think of all those properties files out there in the wild. Wouldn't it be nice to process them with yq? |
I'm always thinking of property files out in the wild. I see them in my dreams :) I think the right way to do it is via expressions. I'll add a
Will add in the next release |
That's a good idea! |
They have already implemented and tested it in less than a day since I raised this issue? |
Fixed in 4.30.1 - https://mikefarah.gitbook.io/yq/operators/array-to-map |
Version of yq: 4.29.2
Operating system: linux
Installed via: binary release
Describe the bug
If a YAML contains keys that are numbers, the roundtrip YAML --> PROP and back PROP --> YAML fails.
This is because numbers are interpreted as array indexes and not as key names. See my feature proposal below.
Input Yaml
Command 1
Step 1: Convert YAML to PROPS
yq --output-format props '.' "$FILE_YAML"
Command 2
Step 2: Convert PROPS back to YAML
yq --input-format props $FILE_PROPS
Expected behavior
Command 2 should generate the input of step 1 to achieve a working roundtrip
Feature proposal
It would be nice if there were new options to control the conversion from PROP to YAML more detailed,
e.g.
--props-number-handling
=[arrayIndex, keyName]
.I love the yq support of property files. However, since it is perfectly valid to use numbers in property files, I consider it an incomplete feature.
The text was updated successfully, but these errors were encountered: