79270757

Date: 2024-12-11 07:05:50
Score: 1
Natty:
Report link

This approach tackles elements in the array in different order without using UDFs. For more documentation refer to https://docs.snowflake.com/en/sql-reference/functions/filter

with input as (
  select parse_json(
    '{"custom": [ { "name": "addressIdNum", "valueNum": 12345678},  {"name": "cancelledDateAt", "valueAt": "2024-04-05 01:02:03" }] }')
  as json)
select
    json:custom as value,
    filter(
            value,
            a -> a:name::string = 'addressIdNum'
    )[0]:valueNum::integer as address_id_num,
    cast(
        filter(
            value,
            a -> a:name::string = 'cancelledDateAt'
    )[0]:valueAt as string)::timestamp as cancelled_date_at
from input;


Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: neeru0303