title: How to escape characters in part of a JSON POST request with CURL?
body: <p>So, I'm trying to use a service called Postmark to send a formatted HTML email. They have some API documentation <a href="http://developer.postmarkapp.com/developer-build.html" rel="nofollow">here</a>, and they give this example on how to use CURL:</p>
  
  <pre><code>$: curl -X POST "http://api.postmarkapp.com/email" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-Postmark-Server-Token: ed742D75-5a45-49b6-a0a1-5b9ec3dc9e5d" \
  -v \
  -d "{From: 'sender@example.com', To: 'receiver@example.com', Subject: 'Postmark test', HtmlBody: '&lt;html&gt;&lt;body&gt;&lt;strong&gt;Hello&lt;/strong&gt; dear Postmark user.&lt;/body&gt;&lt;/html&gt;'}"
  </code></pre>
  
  <p>So, that's all good and works just fine when I use my own token. The problem is when I add my own HtmlBody. If I send a simple message, it works just fine. As soon as I add certain special characters, it breaks. For example, if I do something like this:</p>
  
  <pre><code>-d "{From: 'sender@example.com', To: 'receiver@example.com', Subject: 'Postmark test', HtmlBody: '&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;body&gt;&lt;strong&gt;Hello&lt;/strong&gt; dear Postmark user.&lt;/body&gt;&lt;/html&gt;'}"
  </code></pre>
  
  <p>It breaks because of the <code>!</code>. How can I fix this?</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>: As <em>sourcejedi</em> pointed out I am running this from the shell (bash), so the <code>!</code> issue makes sense to me now. I moved the JSON string to a separate file called email.json and loaded that using <code>-d @email.json</code>. That worked for a simple email with <code>&lt;!DOCTYPE&gt;</code>, but I'm still getting the following error when I try to load the full HTML:</p>
  
  <pre><code>{"ErrorCode":402,"Message":"Received invalid JSON input."}
  </code></pre>
  
  <p>I believe this has to do with some other special characters. I get the same error when I use <code>--data-urlencode @email.json</code>.</p>