diff --git a/pkg/yqlib/doc/usage/properties.md b/pkg/yqlib/doc/usage/properties.md index 6eed4ef0..50217032 100644 --- a/pkg/yqlib/doc/usage/properties.md +++ b/pkg/yqlib/doc/usage/properties.md @@ -230,6 +230,23 @@ person: - pizza ``` +## Decode properties: numbers +All values are assumed to be strings when parsing properties, but you can use the `from_yaml` operator on all the strings values to autoparse into the correct type. + +Given a sample.properties file of: +```properties +a.b = 10 +``` +then +```bash +yq -p=props ' (.. | select(tag == "!!str")) |= from_yaml' sample.properties +``` +will output +```yaml +a: + b: 10 +``` + ## Decode properties - array should be a map If you have a numeric map key in your property files, use array_to_map to convert them to maps. diff --git a/pkg/yqlib/properties_test.go b/pkg/yqlib/properties_test.go index e9673450..9ae5748b 100644 --- a/pkg/yqlib/properties_test.go +++ b/pkg/yqlib/properties_test.go @@ -227,7 +227,14 @@ var propertyScenarios = []formatScenario{ expected: "- person\n- name\n", scenarioType: "decode", }, - + { + description: "Decode properties: numbers", + subdescription: "All values are assumed to be strings when parsing properties, but you can use the `from_yaml` operator on all the strings values to autoparse into the correct type.", + input: "a.b = 10", + expression: " (.. | select(tag == \"!!str\")) |= from_yaml", + expected: "a:\n b: 10\n", + scenarioType: "decode", + }, { description: "Decode properties - array should be a map", subdescription: "If you have a numeric map key in your property files, use array_to_map to convert them to maps.",