Hi @vgautam ,

Please ignore the above code and use below code

%sql
WITH data AS (
  SELECT parse_json('{"key1": "value", "key2": 123}') AS variant_col
)
SELECT 
  -- Check if the key 'key3' exists and its type
  CASE 
    WHEN variant_get(variant_col, '$.key3') IS NULL THEN 'Key Not Found'
    WHEN try_variant_get(variant_col, '$.key3', 'string') IS NULL THEN 'Type Mismatch'
    ELSE 'Valid Cast'
  END AS key3_existence,

  -- Check if the key 'key1' exists and its type
  CASE
    WHEN variant_get(variant_col, '$.key1') IS NULL THEN 'Key Not Found'
    WHEN try_variant_get(variant_col, '$.key1', 'string') IS NULL THEN 'Type Mismatch'
    ELSE 'Valid Cast'
  END AS key1_type_check
FROM data;

View solution in original post