1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Fixed empty array op

This commit is contained in:
Mike Farah
2020-11-22 13:50:32 +11:00
parent aed598c736
commit 3f04a1b52e
15 changed files with 45 additions and 82 deletions

View File

@@ -100,7 +100,7 @@ a:
```
then
```bash
yq eval '.a[] | select(. == "apple") |= "frog"' sample.yml
yq eval '.a.[] | select(. == "apple") |= "frog"' sample.yml
```
will output
```yaml

View File

@@ -10,6 +10,7 @@ yq eval --null-input '[]'
```
will output
```yaml
[]
```
## Collect single

View File

@@ -34,7 +34,7 @@ pets:
```
then
```bash
yq eval '{.name: .pets[]}' sample.yml
yq eval '{.name: .pets.[]}' sample.yml
```
will output
```yaml
@@ -57,7 +57,7 @@ pets:
```
then
```bash
yq eval '{.name: .pets[]}' sample.yml
yq eval '{.name: .pets.[]}' sample.yml
```
will output
```yaml

View File

@@ -1,53 +0,0 @@
## Retrieve a document index
Given a sample.yml file of:
```yaml
a: cat
---
a: frog
```
then
```bash
yq eval '.a | documentIndex' sample.yml
```
will output
```yaml
0
---
1
```
## Filter by document index
Given a sample.yml file of:
```yaml
a: cat
---
a: frog
```
then
```bash
yq eval 'select(. | documentIndex == 1)' sample.yml
```
will output
```yaml
a: frog
```
## Print Document Index with matches
Given a sample.yml file of:
```yaml
a: cat
---
a: frog
```
then
```bash
yq eval '.a | ({"match": ., "doc": (. | documentIndex)})' sample.yml
```
will output
```yaml
match: cat
doc: 0
match: frog
doc: 1
```

View File

@@ -26,7 +26,7 @@ a:
```
then
```bash
yq eval '(.a[] | select(. == "*at")) |= "rabbit"' sample.yml
yq eval '(.a.[] | select(. == "*at")) |= "rabbit"' sample.yml
```
will output
```yaml