title: How to pass an array of JSON (or JSON array) to pg function to be INSERTed into a Table?
body: <p>Function to insert rows of json array into a table:</p>
  <pre><code>create table mytable(col1 text, col2 boolean, col3 boolean);
  create function fun1(vja json[])
  ... as $$
  begin
    foreach v in array json_array_elements(vja)
    loop
      insert into mytable(col1, col2, col3)
      values(v-&gt;'col1', v-&gt;'col2'::boolean, v-&gt;'col3'::boolean);
    end loop;
  end;
  $$;
  </code></pre>
  <p>Call this function:</p>
  <pre><code>select fun1('[
      {&quot;col1&quot;: &quot;turow1@af.com&quot;, &quot;col2&quot;: false, &quot;col3&quot;: true}, 
      {&quot;col1&quot;: &quot;xy2@af.com&quot;, &quot;col2&quot;: false, &quot;col3&quot;: true} 
      ]')
  </code></pre>
  <p>or this form:</p>
  <pre><code>select fun1('[
      {&quot;col1&quot;: &quot;turow1@af.com&quot;, &quot;col2&quot;: &quot;false&quot;, &quot;col3&quot;: &quot;true&quot;}, 
      {&quot;col1&quot;: &quot;xy2@af.com&quot;, &quot;col2&quot;: &quot;false&quot;, &quot;col3&quot;: &quot;true&quot;}, 
      ]')
  </code></pre>
  <p>or this form:</p>
  <pre><code>select fun1('[
      {&quot;col1&quot;: &quot;turow1@af.com&quot;, &quot;col2&quot;: &quot;false&quot;, &quot;col3&quot;: &quot;true&quot;}, 
      {&quot;col1&quot;: &quot;xy2@af.com&quot;, &quot;col2&quot;: &quot;false&quot;, &quot;col3&quot;: &quot;true&quot;}, 
      ]'::json[])
  </code></pre>
  <p>Always received:</p>
  <blockquote>
  <pre><code>ERROR:  malformed array literal: &quot;[
    {&quot;col1&quot;: &quot;turow1@af.com&quot;, &quot;col2&quot;: &quot;false&quot;, &quot;col3&quot;: &quot;true&quot;}, 
    {&quot;col1&quot;: &quot;xy2@af.com&quot;, &quot;col2&quot;: &quot;false&quot;, &quot;col3&quot;: &quot;true&quot;}, 
    ]&quot;
  LINE 2:  '[
           ^
  DETAIL:  &quot;[&quot; must introduce explicitly-specified array dimensions.
  SQL state: 22P02
  Character: 136
  </code></pre>
  </blockquote>