Array to Map
(.[] | select(. != null) ) as $i ireduce({}; .[$i | key] = $i)Simple example
cool:
- null
- null
- helloyq '.cool |= array_to_map' sample.ymlcool:
2: helloLast updated
Use this operator to convert an array to..a map. The indices are used as map keys, null values in the array are skipped over.
Behind the scenes, this is implemented using reduce:
(.[] | select(. != null) ) as $i ireduce({}; .[$i | key] = $i)Given a sample.yml file of:
cool:
- null
- null
- hellothen
yq '.cool |= array_to_map' sample.ymlwill output
cool:
2: helloLast updated