I am using the bash to json parser jq
Considering the following command:
jq '. * .transitive | del(.transitive) | del(.scope,.scopedName)' package.json > package.github.json$$
And the following input:
{
"name": "navigation",
"transitive": {
"name": "navigation",
"scope": "bs",
"scopedName": "@bs/navigation"
}
}
I am trying to get the following output:
{
"name": "@bs/navigation"
}
Is there a way before doing the delete of .scopedName
, to use it's value to set .name
?
Transforming your input to your output is as simple as:
...and of course you could just reorder things to set
name
before deletingtransitive
:That said, if you really want to use
del()
first, you can save content in a variable and use it later: