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

slice: add a --json flag for JSON output #1718

Closed
rzmk opened this issue Apr 3, 2024 · 4 comments · Fixed by #1729
Closed

slice: add a --json flag for JSON output #1718

rzmk opened this issue Apr 3, 2024 · 4 comments · Fixed by #1729
Assignees
Labels
enhancement New feature or request

Comments

@rzmk
Copy link
Collaborator

rzmk commented Apr 3, 2024

Is your feature request related to a problem? Please describe.
My task requires outputting a part of a dataset as JSON and currently I use qsv slice for this, however I need to convert the sliced data to a valid JSON format which is an extra step.

Describe the solution you'd like
A --json flag for qsv slice with the output formatted like sqlp's --format json flag. No need for pretty-printing the output (could be another flag).

Describe alternatives you've considered
Potentially combining commands or if sqlp has a way to slice data based on start and end row number. Though for my purposes a --json flag would likely be the easiest to work with.

@jqnatividad jqnatividad added the enhancement New feature or request label Apr 4, 2024
@jqnatividad jqnatividad self-assigned this Apr 5, 2024
@jqnatividad
Copy link
Owner

Hi @rzmk ,

To confirm, do you want the JSON as a JSON array of arrays or as JSONL, where each JSON record is separated by newlines.

@rzmk
Copy link
Collaborator Author

rzmk commented Apr 5, 2024

An array of dictionaries where the keys of each dictionary are the headers and the values of each dictionary are that row's values.

@jqnatividad
Copy link
Owner

@rzmk, I did an implementation and it's a bit kludgy. Will keep tweaking it but have you tried piping the output of slice to qsv tojsonl?

Do you intend to use the JSON with DataTables that's why you need it in JSON array format?

@jqnatividad
Copy link
Owner

After tweaking it a bit, the implementation is much better now. The only thing it doesn't do is infer JSON types with everything as a JSON string, which for your use case, may not be required.

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

Successfully merging a pull request may close this issue.

2 participants