I actually have 2 arrays in bash that contains string values. Something like that :
Array1=(Kevin Paul)
Array2=(OK DANGER)
I would like to create a json with 2 attributes, something like that if possible
{
"results":[
{
"nom":"Kevin",
"status":"OK"
},
{
"nom":"Paul",
"status":"Danger"
}
]
}
I read a lot speaking about JQ that i alreay use for my arrays, but no one speak about something like i want :(
One of my test ( that does not respond to what i would like ) :
declare -a test_array
declare -a test_array2
test_array=(apple orange lemon)
test_array2=(DANGER OK WARNING)
echo ${test_array[0]}
echo '['
printf '{"CVEC": "%s", "LVL" : "%s"},\n' "${test_array[@]}, ${test_array2[@]}" | sed '$s/,$//'
echo ']'
Display
[
{"CVEC": "apple", "LVL" : "orange"},
{"CVEC": "lemon, DANGER", "LVL" : "OK"},
{"CVEC": "WARNING", "LVL" : ""}
]