1

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
4
  • Care to post your bash code? Commented Oct 4, 2015 at 14:45
  • Have you seen this post stackoverflow.com/questions/7172784/… Commented Oct 4, 2015 at 14:50
  • Sorry for the editing i was using mobile, thanks Commented Oct 4, 2015 at 14:54
  • By the way, you should be using --arg instead of interpolating shell variables in your jq script. Commented Oct 4, 2015 at 16:00

1 Answer 1

2

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 ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.