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

Preserve order of keys in JSON lists #388

Open
rubenvereecken opened this issue Feb 15, 2024 · 1 comment
Open

Preserve order of keys in JSON lists #388

rubenvereecken opened this issue Feb 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@rubenvereecken
Copy link

Is your feature request related to a problem? Please describe.
I deal with JSON lists of objects, which I convert to CSV. The key order between the objects is consistent, yet in the output is random.

Describe the solution you'd like
We already have preserved key order for regular objects:

$ echo '{"z":1,"a":2,"c":3}' | dasel -r json -w csv
z,a,c
1,2,3

I would love to have the same feature for lists of objects – ie:

$ echo '[{"z":1,"a":2,"c":3},{"z":1,"a":2,"c":3}]' | dasel -r json -w csv                                                                                                                                                     
z,a,c
1,2,3
1,2,3

Instead, what currently happens is:

$ echo '[{"z":1,"a":2,"c":3},{"z":1,"a":2,"c":3}]' | dasel -r json -w csv                                                                                                                                                     
a,c,z
2,3,1
2,3,1
@rubenvereecken rubenvereecken added the enhancement New feature or request label Feb 15, 2024
@TomWright
Copy link
Owner

This is only an issue when writing to CSV:

$ echo '[{"z":1,"a":2,"c":3},{"z":1,"a":2,"c":3}]' | dasel -r json
[
  {
    "z": 1,
    "a": 2,
    "c": 3
  },
  {
    "z": 1,
    "a": 2,
    "c": 3
  }
]
$ echo '[{"z":1,"a":2,"c":3},{"z":1,"a":2,"c":3}]' | dasel -r json -w yaml
- z: 1
  a: 2
  c: 3
- z: 1
  a: 2
  c: 3

More of a note to myself at the moment - hopefully I can better integrate the CSV parser in use.

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

No branches or pull requests

2 participants