I am new to shell script, I am trying to substitute an array inside an object but its not working.
I am trying to make curl request with dynamic data payload.
case $name in
"test1")
VALUE='[{"test": "1"},{"test": "2"}]'
;;
"test2")
VALUE='[{"test": "1"},{"test": "3"}]'
;;
?)
echo "Error"
exit 1
;;
esac
I am doing a curl like
$(curl -s -X POST \
"${BASE_URL}/pdc/config/add" \
-H "authorization: Bearer ${TOKEN}" \
-H "content-type: application/json" \
-d '{
"data": '\"${VALUE}\"'
}' \
--insecure
)
But this sends the array as a string.
The data to be sent should be like
{"data": [{"test": "1"},{"test": "3"}]}
But right now it is being sent as
{"data": "[{"test": "1"},{"test": "3"}]"}
How can I fix this?
jq.array=( "first value" "second value" ), and it's abash-only feature not available inshat all. The shell doesn't know JSON exists, much less what a JSON array looks like.$( ... )around your command without a good reason to. With curl, that's outright dangerous -- it lets the remote server send back a string your local shell will word-split, glob-expand, and then run as a local command, so whoever runs the server (or is doing a MITM attack against it, or against your network connection, since you're using--insecure) can run code on your machine.