Added properties convert to numbers example #2023

This commit is contained in:
Mike Farah
2024-05-12 12:07:04 +10:00
parent d9adcdb668
commit 0c15cf35a7
2 changed files with 25 additions and 1 deletions
+17
View File
@@ -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.