Skip to content

Support env(XX)[] expressions #2071

@mikefarah

Description

@mikefarah

Discussed in #2069

Originally posted by djthornton1212 June 14, 2024
I've tried different syntax to splat an env() and feel like I'm missing something.

Examples:

Not working

list='["item1", "item2", "item3"]' yq --null-input 'env(list)[]'  # returns Error: bad expression, please check expression syntax
list='["item1", "item2", "item3"]' yq --null-input '[env(list)][]'  # nests the array in an array then splats the second level, returning me to where I began

Working:

list='["item1", "item2", "item3"]' yq --null-input 'env(list) | .[]' # pipe then splat
list='["item1", "item2", "item3"]' yq --null-input '[env(list)][][]' # double splat after nesting

edit:
I've also found that using the as operator allows for correct splatting... is that the word...

list='["item1", "item2", "item3"]' yq --null-input 'env(list) as $list | $list[]'

I guess I'm trying to understand if the working examples are the correct way or is there's another method I should be using.

Thanks,

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions