title: How do I escape a single quote in Ruby?
body: <p>I am passing some JSON to a server via a script (not mine) that accepts the JSON as a string.</p>
  
  <p>Some of the content of the JSON contains single quotes so I want to ensure that any single quotes are escaped before being passed to the script.</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>&gt; irb
  &gt; 1.9.3p194 :001 &gt; x = "that's an awesome string"
  &gt;  =&gt; "that's an awesome string" 
  &gt; 1.9.3p194 :002 &gt; x.sub("'", "\'")
  &gt;  =&gt; "that's an awesome string" 
  &gt; 1.9.3p194 :003 &gt; x.sub("'", "\\'")
  &gt;  =&gt; "thats an awesome strings an awesome string"
  </code></pre>
  
  <p>but can't seem to get the syntax right.</p>