davidnussio / vscode-jq-playground

Visual Code Studio jq playground
https://marketplace.visualstudio.com/items?itemName=davidnussio.vscode-jq-playground
MIT License
46 stars 8 forks source link

Multiple file input #49

Closed jordao76 closed 3 years ago

jordao76 commented 4 years ago

It would be good to support multiple files as input.

davidnussio commented 4 years ago

I never used multiple files as input but it seem interesting feature. Could you give me some command line examples?

Thanks

jordao76 commented 4 years ago

Sure,

I need to concatenate certain JSON files into a single file, and make a JSON object where each key is the original file name and the value is the original file JSON.

I can do this for two files like this:

jq '{ (input_filename|rtrimstr(".json")) : . }' file1.json file2.json | jq -s add

I'm sure there's a way to do it in one jq command, but you get the idea.

What I actually do is read all files in a folder and do that:

ls -I data.json | xargs jq '{ (input_filename|rtrimstr(".json")) : . }' | jq -s add > data.json
davidnussio commented 3 years ago

Better late than never, sorry :) Today I checked out the use case, I think I will release something like this

Screenshot 2021-03-24 184823