title: How do I convert a javascript object to structured jsonb in Postgres?
body: <p>If I have a plain <code>js</code> object like this in my application layer:</p>
  <pre class="lang-js prettyprint-override"><code>{ name: 'amit', age: 44, likes: ['some', 'things']}
  </code></pre>
  <p>I would just do a JSON.stringify on it to get:</p>
  <pre class="lang-json prettyprint-override"><code>&quot;{&quot;name&quot;:&quot;amit&quot;,&quot;age&quot;:44,&quot;likes&quot;:[&quot;some&quot;,&quot;things&quot;]}&quot;
  </code></pre>
  <p>But I want to do this in sql in my postgres db which has a <code>jsonb</code> column.</p>
  <p>I have tried using functions like <code>to_json</code> (which fails) and also tried casting this object like so:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT '{ name: 'amit', age: 44, likes: ['some', 'things']}'::jsonb
  </code></pre>
  <p>But this gives me an error:</p>
  <pre><code>ERROR: ERROR:  syntax error at or near &quot;', age: 44, likes: ['&quot;
  LINE 8: SELECT '{ name: 'amit', age: 44, likes: ['some', 'things']}'.
  </code></pre>
  <p>How do I convert this object to a structured jsonb object which I can store in my table's <code>jsonb</code> column?</p>