Suppose that the output of a jq command is a list of objects. What would be the command to get this list as the attribute of an object? That is: transforming the output from a list into an object.
Example JSON list:
[
{"name":"Foo"},
{"name":"Bar"}
]
Example desired output object:
The attribute "items" has been added, and contains the list that serves as input.
{
"items": [
{"name":"Foo"},
{"name":"Bar"}
]
}
CodePudding user response:
This will take the json document and put it as a "items" attribute of a dictionary.
jq '{items: .}'
Here is a good guide for the basics. https://www.baeldung.com/linux/jq-command-json