Trying to merge an undefined number of JSON files into one, each represented in their own key (using jq
).
Example:
$ cat foo.json
{
"test1":"Foo"
}
$ cat bar.json
{
"test2":"Bar"
}
$ jq -s "{`ls | sed -r 's/\.json$/: \./' | tr '\n' ', ' | sed 's/.$//'`}" `ls`
{
"foo": [
{
"test1": "Foo"
},
{
"test2": "Bar"
}
],
"bar": [
{
"test1": "Foo"
},
{
"test2": "Bar"
}
]
}
As I am trying to output:
{
"foo": {
"test1": "Foo"
},
"bar": {
"test2": "Bar"
}
}
For example: foo
being the name of the first file and expected to be the key for its content in the final output.
(Also, I feel like this is not really pretty to call ls
twice for the same thing, but not sure if there is a way around).