Skip to content

support compact arrary output #2410

Open
@ryenus

Description

@ryenus

Please describe your feature request.
Currently yq always format arrays in block style, it would be nice to have an option to format arrays in flow style, namely compact arrays.

Describe the solution you'd like
If we have data1.yml like:
(please keep to around 10 lines )

numbers:
  - 1
  - 2
  - 3

And we run a command:

yq --compact-array .numbers data1.yml

it could output a json style array, even if the output format is yaml:

[1, 2, 3]

Describe alternatives you've considered
With PyYAML, there's default_flow_style option:

import yaml
data = { 'numbers': [1, 2, 3] }
print(yaml.dump(data['numbers'], default_flow_style=True))

# [1, 2, 3]

Additional context
Ideally, only the array of scalar elements should be printed in compact form.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions