I have the following JSON-array from a json-file:
[
{
"key": "Ley1",
"file": "Filepath1",
"line": 10,
"rule": "csharpsquid:S1643",
"message": "Use a StringBuilder instead.",
"type": "CODE_SMELL"
},
{
"key": "Key2",
"file": "FilePath2",
"line": 12,
"rule": "csharpsquid:S1643",
"message": "Use a StringBuilder instead.",
"type": "CODE_SMELL"
}
]
and I want to add the variable "critical" to all items of it using a bash-command so it looks like this:
[
{
"key": "Key1",
"file": "Filepath1",
"line": 10,
"rule": "csharpsquid:S1643",
"message": "Use a StringBuilder instead.",
"type": "CODE_SMELL",
"critical": "No"
},
{
"key": "Key2",
"file": "FilePath2",
"line": 12,
"rule": "csharpsquid:S1643",
"message": "Use a StringBuilder instead.",
"type": "CODE_SMELL",
"critical": "Yes"
}
]
Unfortunately I am a complete JSON and bash beginner and could not find a bash-command solving this problem. I tried a litte bit with jq on jq-play but it did not really lead to something so I wanted to try it here. I hope this are all information needed, so does anyone know maybe a command for this?
EDIT: This here worked, thanks!
.[] |= . + {"critical": "No"}
But no i want to determine the value of "yes" or "no" depending on the file-value. Do you know how to edit the command so it checks the file-value in order to determine the critical-value?
It should decide like this:
Filepath1, Filepath3 leads to "critical" : "No"
and
Filepath2, Filepath4, Filepath5 leads to "critical" : "Yes"