Added properties convert to numbers example #2023

This commit is contained in:
Mike Farah 2024-05-12 12:06:35 +10:00
parent d9adcdb668
commit 0c15cf35a7
2 changed files with 25 additions and 1 deletions

View File

@ -230,6 +230,23 @@ person:
- pizza - 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 ## 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. If you have a numeric map key in your property files, use array_to_map to convert them to maps.

View File

@ -227,7 +227,14 @@ var propertyScenarios = []formatScenario{
expected: "- person\n- name\n", expected: "- person\n- name\n",
scenarioType: "decode", 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", 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.", subdescription: "If you have a numeric map key in your property files, use array_to_map to convert them to maps.",