I have a json file like this:
{
"arrays": [
{
"name": "foo",
"properties": [
{
"type": "app",
"url": "https://example.com",
"checksum": "d6fd580fe890b826250aa5d5a88bcdb28839cff4d447ba51536cda4ceae89c4e"
}
]
}
]
}
I want to change the type to something else, delete the url and checksum key and add a file key in their place with a value.
The final thing should be:
{
"arrays": [
{
"name": "foo",
"properties": [
{
"type": "Bar",
"file": "filename"
}
]
}
]
}
How would I do this inline with jq
I got upto modifying the type value:
jq '(.arrays[]| select(.name == "foo").properties[]).type |= "Bar"' test.json
2
Answers
Will result in:
Try it online!
I would replace the whole properties field :
You can try it here.