mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-07 02:48:27 +08:00
Update document generation script
This commit is contained in:
+9
-50
@@ -2,23 +2,17 @@
|
||||
|
||||
Similar to the same named functions in `jq` these functions convert to/from an object and an array of key-value pairs. This is most useful for performing operations on keys of maps.
|
||||
|
||||
## to\_entries Map
|
||||
|
||||
## to_entries Map
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
a: 1
|
||||
b: 2
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'to_entries' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
- key: a
|
||||
value: 1
|
||||
@@ -26,23 +20,17 @@ will output
|
||||
value: 2
|
||||
```
|
||||
|
||||
## to\_entries Array
|
||||
|
||||
## to_entries Array
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- a
|
||||
- b
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'to_entries' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
- key: 0
|
||||
value: a
|
||||
@@ -50,113 +38,84 @@ will output
|
||||
value: b
|
||||
```
|
||||
|
||||
## to\_entries null
|
||||
|
||||
## to_entries null
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
null
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'to_entries' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
```
|
||||
|
||||
## from\_entries map
|
||||
|
||||
## from_entries map
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
a: 1
|
||||
b: 2
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'to_entries | from_entries' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
a: 1
|
||||
b: 2
|
||||
```
|
||||
|
||||
## from\_entries with numeric key indexes
|
||||
|
||||
from\_entries always creates a map, even for numeric keys
|
||||
## from_entries with numeric key indexes
|
||||
from_entries always creates a map, even for numeric keys
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- a
|
||||
- b
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'to_entries | from_entries' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
0: a
|
||||
1: b
|
||||
```
|
||||
|
||||
## Use with\_entries to update keys
|
||||
|
||||
## Use with_entries to update keys
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
a: 1
|
||||
b: 2
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'with_entries(.key |= "KEY_" + .)' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
KEY_a: 1
|
||||
KEY_b: 2
|
||||
```
|
||||
|
||||
## Use with\_entries to filter the map
|
||||
|
||||
## Use with_entries to filter the map
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
a:
|
||||
b: bird
|
||||
c:
|
||||
d: dog
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'with_entries(select(.value | has("b")))' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
a:
|
||||
b: bird
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user