title: What is the difference between as_json vs JSON.parse?
body: <p>Could someone please specify difference between <code>as_json</code> and <code>JSON.parse</code>?<br />
  The only difference is that <code>JSON.parse</code> part of Ruby Standard Library and <code>as_json</code> part of Rails ActiveSupport?</p>
  <p>Rails console:</p>
  <pre><code>irb(main):001:0&gt; json_str = &quot;{\&quot;foo\&quot;: {\&quot;bar\&quot;: 1, \&quot;baz\&quot;: 2}, \&quot;bat\&quot;: [0, 1, 2]}&quot;
  irb(main):002:0&gt; puts JSON.parse(json_str)
  {&quot;foo&quot;=&gt;{&quot;bar&quot;=&gt;1, &quot;baz&quot;=&gt;2}, &quot;bat&quot;=&gt;[0, 1, 2]}
  irb(main):003:0&gt; puts json_str.as_json
  {&quot;foo&quot;: {&quot;bar&quot;: 1, &quot;baz&quot;: 2}, &quot;bat&quot;: [0, 1, 2]}
  </code></pre>
  <p>Ref:</p>
  <ul>
  <li><a href="https://ruby-doc.org/stdlib-3.1.2/libdoc/json/rdoc/JSON/Ext/Parser.html#method-i-parse" rel="nofollow noreferrer">https://ruby-doc.org/stdlib-3.1.2/libdoc/json/rdoc/JSON/Ext/Parser.html#method-i-parse</a></li>
  <li><a href="https://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html#method-i-as_json" rel="nofollow noreferrer">https://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html#method-i-as_json</a></li>
  </ul>