title: JSON Object with variables into PostgreSQL
body: <p>I have the following function:</p>
  
  <pre><code>create or replace function something(id integer)
    RETURNS INTEGER
  language plpgsql
  as $$
    DECLARE
    name varchar;
    email varchar;
    route varchar;
    now timestamp;
    BEGIN
      now = current_timestamp;
      SELECT apd.apd_nome, apd.apd_email, CAST(r.rota_params-&gt;&gt;'url_completa' as varchar) into name, email, route FROM avise_produto_disponivel apd
        inner join produto p on apd.pro_id = p.pro_id
        inner join produto_div div on p.pro_id = div.pro_id
        inner join produto_oferta_div pod on div.pod_id = pod.pod_id
        inner join produto_oferta po on po.ofe_id = pod.ofe_id
        inner join rotas r on CAST(r.rota_params-&gt;&gt;'oferta_id' as integer) = po.ofe_id
      where apd.pro_id = $1;
      DELETE FROM avise_produto_disponivel where pro_id = $1;
      rota = CONCAT('https://www.something.com/', route);
      INSERT INTO comunicacao (cot_id, com_para, com_assunto, com_data_criado, com_parametros, com_para_nome, cos_id, com_de) VALUES (1, email, 'Produto Chegou', now, '{"NOME": name, "URL": route}', name, 1, 'correio');
      return 1;
    END;
  $$ ;
  </code></pre>
  
  <p>But when I try to execute I get the following error:</p>
  
  <pre><code>[22P02] ERROR: invalid input syntax for type json Detalhe: Token "nome" is invalid. Where: JSON data, line 1: {"NOME": name... PL/pgSQL function avise_me(integer) line 18 at SQL statement
  </code></pre>
  
  <p>Thanks in advance.</p>