Reputation: 425
I have a shell variable which contains json as follows
{ "test" :"test", "temp":"temp" }
This is a part of json that I got when parsed from jq, which is a json parser tool.But when I pass this to curl as a part of post request body, it is getting converted to
'{'
'"test"' ':' 'test,'
'"temp"' ':' 'temp'
'}'
But I want it as
'{
"test" : "test",
"temp" : "temp"
}'
VAL=$(echo "$RET" | jq ".pending[$j].value")
VAL is the variable that will contain the json I need to pass this VAL as request body to curl
curl -X POST -H "$CONTENT_HEADER" -H "$AUTH_HEADER" http://localhost:8080/testApi -d $VAL
Upvotes: 1
Views: 6870
Reputation:
The shell is interpreting it as several arguments. Either quote the expansion (as in -d "$VAL"
) or pipe it instead of saving it to a variable jq '...' | curl ...
Upvotes: 2