mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Added properties convert to numbers example #2023
This commit is contained in:
parent
d9adcdb668
commit
0c15cf35a7
@ -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.
|
||||||
|
|
||||||
|
@ -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.",
|
||||||
|
Loading…
Reference in New Issue
Block a user