title: Ruby to_yaml stringifies my json
body: <p>I am trying to convert a ruby hash to yaml. I'd like part of the hash be valid json; however, when I try to serialize the json string, it is converted to yaml in quotes.</p>
  
  <p>For example, when I just have a simple string, the ouput is as follows (note <code>foo</code> is not in quotations):</p>
  
  <pre><code>request = {}
  request['body'] = 'foo'
  request.to_yaml # outputs: body: foo
  </code></pre>
  
  <p>However, when I add something to the beginning of the string, like <code>{ foo</code> the output for body gets quoted:</p>
  
  <pre><code>request['body'] = '{ foo'
  request.to_yaml # outputs: body: '{ foo'
  </code></pre>
  
  <p>How can I get around this? I've tried <code>JSON.parse</code> and, though that make work, I can't be guaranteed that this input will actually be json (could be xml, etc...) -- I just want to give back whatever was given to me but not "stringified".</p>
  
  <p>Basically, I want to give an object that looks like:</p>
  
  <pre><code>{ 'request' =&gt; {
      'url' =&gt; '/posts',
      'method' =&gt; 'GET',
      'headers' =&gt; [
        'Content-Type' =&gt; 'application/json'
      ]
    },
    'response' =&gt; {
      'code' =&gt; 200,
      'body' =&gt; '[{"id":"ef4b3a","title":"this is the title"},{"id":"a98c4f","title":"title of the second post"}]'
    }
  }
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code>request:
      url: /posts
      method: GET
      headers:
          - Content-Type: application/json
  
  response:
      code: 200
      body:
          [{"id":"ef4b3a","title":"this is the title"},{"id":"a98c4f","title":"title of the second post"}]
  </code></pre>
  
  <p>The reason being: right now, I can go from yaml to the correct ruby hash but I can't go the other way.</p>