jsphdnl
jsphdnl

Reputation: 425

Converting json string in a shell variable to string literal

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

Answers (1)

user3899165
user3899165

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

Related Questions