title: How to convert a string `to_json` and `to_xml` using Ruby on Rails?
body: <p>I am using Ruby on Rails 3 and I would like, in some way, to convert a string <code>to_json</code> and <code>to_xml</code>.</p>
  
  <p>Just to know, I need to return that string in a Rack method in this way:</p>
  
  <pre><code>[404, {"Content-type" =&gt; "application/json"}, ["Bad request"]]
  # or
  [404, {"Content-type" =&gt; "application/xml"}, ["Bad request"]]
  </code></pre>
  
  <p>However what I need is only to convert that string <code>to_json</code> and <code>to_xml</code>? <strong>How is it possible do that?</strong> </p>