Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
How to manipulate Json nested attributes in a JavaScript UDF in Snowflake

I have to write a JavaScript UDF function in Snowflake that receives a variant as the argument and do some value changes for a few keys. All is good but there's one particular attribute (PROPERTY) that looks like a nested JSON but it has some have escapes (backslash) which add some complexity because one of the requirements is to transform the value for "PROP_3" (nested attribute within PROPERTY). See screen shot. Any ideas how to approach this request taking the screen shot as the input for the UDF?

input format for the UDF argument Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I tend to avoid UDFs when straight SQL approaches are available. There are rare times when procedural code can outperform straight SQL by doing less work, but that's uncommon.

create or replace temp table t1 as select 
parse_json($$ {"KEY":"ABCD","PROPERTY":"{\"PROP1\":\"VALUE1\",\"PROP2\":\"VALUE2\",\"PROP3\":\"VALUE3\",\"PROP4\":null}","ATTR_1":0,"ATTR_2":"customer"} $$) as V;

select 
     object_insert(V, 'PROPERTY', object_insert(parse_json(V:PROPERTY), 'PROP3', 'NEW_VALUE', true), true) as JSON
from t1;

If you need to convert PROP3 back to a string property, you can create a very simple JavaScript UDF that applies the JSON.stringify() method.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda