i have the following json
{
"name" : "qwerty",
"values" :[
{
"field1" : [
"val1"
],
"field2" : [
"val2"
],
"name1" : [["a", "b"], ["c", "d"]]
},
{
"field1" : [
"val3"
],
"field2" : [
"val4"
],
"name1" : [["a", "b"], ["c", "d"]]
},
{
"field1" : [
"val5"
],
"field2" : [
"val6"
],
"name1" : [["a", "b"], ["c", "d"]]
}
]
}
I need to change the above json to the following using jq in bash
{
"name" : "qwerty",
"values" :[
{
"field1" : "val1",
"field2" : "val2",
"new_name" : [["a", "b"], ["c", "d"]]
},
{
"field1" : "val3",
"field2" : "val4",
"new_name" : [["a", "b"], ["c", "d"]]
},
{
"field1" : "val5",
"field2" : "val6",
"new_name" : [["a", "b"], ["c", "d"]]
}
]
}
Here i am facing the following issues :
I tried parsing the inner json with tag values and replace the '[' ']' with spaces, however, when i try to put the "values" in a variable in the form of list, jq is prettifying and then showing each new line as a element of an array.
The number of inner jsons in the values array is not fixed.
Can some one please help me with framing the jq statement to be run in bash to make the required changes.