Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatten array of maps to create tsv format #2271

Open
ckuenne opened this issue Jan 29, 2025 · 0 comments
Open

flatten array of maps to create tsv format #2271

ckuenne opened this issue Jan 29, 2025 · 0 comments

Comments

@ckuenne
Copy link

ckuenne commented Jan 29, 2025

i'm trying to collapse/flatten a structure so i can convert to tsv format.

Version of yq: 4.45.1
Operating system: Debian 11
Installed via: wget binary release

test.yml:

- name: Miller, Tim
  email: [email protected]
  user_metadata:
    username: tmiller
    x: 1
- name: Jones, Karen
  email: [email protected]
  user_metadata:
    username: kjones
    y: 2

this works as long as i ignore the map "user_metadata":

yq -o tsv '.[] |= pick(["name","email"])' test.yml
->
name	email
Miller, Tim	[email protected]
Jones, Karen	[email protected]

but i also need to flatten the map inside the array (basically remove the first level) and then select from the remaining keys. this is my desired output:

name	email	username
Miller, Tim	[email protected]	tmiller
Jones, Karen	[email protected]	kjones

it's probably not difficult but i'm out of ideas...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant