yq/pkg/yqlib/doc/Entries.md

780 B

to_entries Map

Given a sample.yml file of:

a: 1
b: 2

then

yq eval 'to_entries' sample.yml

will output

- key: a
  value: 1
- key: b
  value: 2

to_entries Array

Given a sample.yml file of:

- a
- b

then

yq eval 'to_entries' sample.yml

will output

- key: 0
  value: a
- key: 1
  value: b

from_entries map

Given a sample.yml file of:

a: 1
b: 2

then

yq eval 'to_entries | from_entries' sample.yml

will output

a: 1
b: 2

from_entries with numeric key indexes

from_entries always creates a map, even for numeric keys

Given a sample.yml file of:

- a
- b

then

yq eval 'to_entries | from_entries' sample.yml

will output

0: a
1: b