I am trying to use bash to create a string variable that will be used in jq to add new elements to the json file. But it's escaping my double quote. See below for "wrong output" produced. I am expecting the output shown below "expected output". What is the correct way to add more fields to filename with bash variable?
My input json file (input.json):
{
"##_Comment1": "Inputs",
"filename": [
"file1",
"file2",
"file3",
"file4"
]
}
My bash script:
#!/bin/bash
update_list='"abc","efg"'
cat input.json | jq --arg args "$update_list" '.["filename"] += [$args]'
wrong output:
{
"##_Comment1": "Inputs",
"filename": [
"file1",
"file2",
"file3",
"file4",
"\"abc\",\"efg\""
]
}
correct output:
{
"##_Comment1": "Inputs",
"filename": [
"file1",
"file2",
"file3",
"file4",
"abc",
"efg"
]
}