title: Store Array of Json Objects In Postgresql Using Python
body: <p>I am currently trying to store two lists of json objects into my postgresql database using psycopg2 without success.</p>
  
  <p>Here's a snippet of what I am trying to do...</p>
  
  <pre><code>SQL_INSERT_QUERY = """INSERT INTO table (
                                x,
                                json_list_one,
                                json_list_two
                              ) VALUES (%s, %s, %s)"""
  
  def insert_stuff(id, json_list_one, json_list_two):
  values = (
      id,
      map(psycopg2.extras.Json, json_list_one),
      map(psycopg2.extras.Json, json_list_two)
  )
  conn = get_connection_pool().getconn()
  try:
      cur = conn.cursor()
      cur.execute(SQL_INSERT_QUERY, values)
      conn.commit()
      cur.close()
  finally:
      get_connection_pool().putconn(conn)
  </code></pre>
  
  <p>This current implementation is resulting in this error...</p>
  
  <pre><code>An exception of type ProgrammingError occured. Arguments:
  ('column "json_list_one" is of type json[] but expression is of type text[]\nLINE 5: ...) VALUES (\'9527d790-31dc-46fa-b683-c6fc9807c2a4\', ARRAY[\'{"h...\n                                                             ^\nHINT:  You will need to rewrite or cast the expression.\n',)
  </code></pre>
  
  <p>Does anyone know how I am supposed to insert an array of json objects in PostgreSQL?</p>
  
  <p>Thank you.</p>