title: How do you POST an entire json string from a bash variable with curl?
body: <p>I'm trying to POST data from a bash variable using curl, however, I'm unable to get this to work. This is the command that I'm using:</p>
  
  <pre><code>escape() { printf "%q" "$1"; }    
  
  curl -d "$(escape "$client")" -X POST -v https://$server/clients
  </code></pre>
  
  <p>The client variable look like this:</p>
  
  <pre><code>{"roles":["test"],"softwareName":"Some Soft","passwordSalt":"aaa","clientID":"full-client-2","contactPerson":"Test","contactPersonEmail":"a@b.org","description":"test","name":"Full Client-2","organization":"Some Org","passwordAlgorithm":"sha512","passwordHash":"bbb"}
  </code></pre>
  
  <p>And on the server I'm receiving the following:</p>
  
  <pre><code>{ '{"roles":': { '"test"': { '\"test\"\': '' } } }
  </code></pre>
  
  <p>I think its a problem with the escaping but I can't figure this out.</p>
  
  <p>I've had a look at a number of other questions about this on here, but it seems most people need to insert variable into a literal that they are then trying to post. My problem is around using an entire variable as the json body. I've tried to use their answers to help me out but I haven't had any luck so far.</p>