title: How to send a Ruby hash object with objects as keys to front end Javascript as a Map object
body: <p>Javascript doesn't support having objects as object keys, but the Map object does. My question is, is there a way to easily send such an object from back end to front end?</p>
  <pre><code>def test_controller
    object = {&quot;a&quot;=&gt;1,&quot;b&quot;=&gt;2}
    front_end_object = {object =&gt; 5}
    render json: front_end_object, status: 200
  end
  
  $.ajax({
    type:&quot;POST&quot;,
    url: &quot;/pull_from_test_controller&quot;,
    dataType:&quot;json&quot;,
    contentType:&quot;application/json&quot;,
    data: {},
    success: function(response, status_string, jqxhr) {
       console.log(response)
    }
  })
  
  </code></pre>
  <p>The <code>response</code> that's logged in front end, as expected, since it was converted to JSON, has the <code>object</code> built in the backend as a string key.</p>
  <pre><code>// console response
  response = {{&quot;a&quot;=&gt;&quot;1&quot;,&quot;b&quot;=&gt;&quot;2&quot;}: 5}
  // further inspection
  Object.keys(response)[0] = &quot;{\&quot;a\&quot;=&gt;\&quot;1\&quot;, \&quot;b\&quot;=&gt;\&quot;2\&quot;}&quot;
  </code></pre>
  <p>Is there some way to easily convert this in front end to a Map object to again have an object as a key, or perhaps in the rendering process indicate this?</p>
  <p>My current solution is just to JSON.parse, but this seems clunky</p>
  <pre><code>JSON.parse(Object.keys(response)[0])
  </code></pre>