mirror of
https://github.com/mikefarah/yq.git
synced 2025-02-26 01:25:45 +00:00
Added nested traversal examples
This commit is contained in:
parent
b6e2a96ead
commit
78af68f436
@ -63,6 +63,22 @@ will output
|
|||||||
frog
|
frog
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Multiple special characters
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a:
|
||||||
|
"key.withdots":
|
||||||
|
"another.key": apple
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq eval '.a["key.withdots"]["another.key"]' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
apple
|
||||||
|
```
|
||||||
|
|
||||||
## Keys with spaces
|
## Keys with spaces
|
||||||
Use quotes with brackets around path elements with special characters
|
Use quotes with brackets around path elements with special characters
|
||||||
|
|
||||||
@ -211,6 +227,21 @@ will output
|
|||||||
1
|
1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Traversing nested arrays by index
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- []
|
||||||
|
- - cat
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq eval '.[1][0]' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
cat
|
||||||
|
```
|
||||||
|
|
||||||
## Maps with numeric keys
|
## Maps with numeric keys
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -77,6 +77,14 @@ var traversePathOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[{}], (!!str)::frog\n",
|
"D0, P[{}], (!!str)::frog\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Multiple special characters",
|
||||||
|
document: `a: {"key.withdots": {"another.key": apple}}`,
|
||||||
|
expression: `.a["key.withdots"]["another.key"]`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[a key.withdots another.key], (!!str)::apple\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Keys with spaces",
|
description: "Keys with spaces",
|
||||||
subdescription: "Use quotes with brackets around path elements with special characters",
|
subdescription: "Use quotes with brackets around path elements with special characters",
|
||||||
@ -244,6 +252,14 @@ var traversePathOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[0], (!!int)::1\n",
|
"D0, P[0], (!!int)::1\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Traversing nested arrays by index",
|
||||||
|
document: `[[], [cat]]`,
|
||||||
|
expression: `.[1][0]`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[1 0], (!!str)::cat\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Maps with numeric keys",
|
description: "Maps with numeric keys",
|
||||||
document: `{2: cat}`,
|
document: `{2: cat}`,
|
||||||
|
Loading…
Reference in New Issue
Block a user