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

Is there a way to "sparsify" #1497

Closed
seancarmody opened this issue Feb 17, 2024 · 3 comments · Fixed by #1498
Closed

Is there a way to "sparsify" #1497

seancarmody opened this issue Feb 17, 2024 · 3 comments · Fixed by #1498

Comments

@seancarmody
Copy link

Is there any way to do the reverse of unsparsify when converting from CSV to JSON? Where there are missing values in for a column in the CSV file, I would like to omit the key completely from that record in the JSON output. For example, taking as input

A,B,C
1,2,3
4,,5

the output should be

[
{
  "A": 1,
  "B": 2,
  "C": 3
},
{
  "A": 4,
  "C": 5
}
]

I can get the desired result by using mlr --c2j cat and piping the result through jq 'map(with_entries(select(.value != "")))' but it would be nice to be able to do it all in miller.

@johnkerl
Copy link
Owner

Oh wow nice 😎

@johnkerl johnkerl self-assigned this Feb 17, 2024
@johnkerl
Copy link
Owner

@seancarmody what do you think of #1498?

@seancarmody
Copy link
Author

That works a treat. Thank you for responding to this so quickly.

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

Successfully merging a pull request may close this issue.

2 participants