Class JsonTypeHelper

java.lang.Object
dev.frostlake.functions.scalar.JsonTypeHelper

public final class JsonTypeHelper extends Object
Shared utilities for JSON variant type-checking functions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    DROP every backslash that does not begin a valid JSON escape (i.e. is not followed by one of the characters " \ / b f n r t u) — live-verified: Snowflake's PARSE_JSON turns "a\d+" into ad+, discarding the invalid backslash rather than keeping it.
    static tools.jackson.databind.JsonNode
    parse(Object value)
     
    static tools.jackson.databind.JsonNode
    Parse JSON the way Snowflake tolerates it: strictly first, and on failure retry after relaxing the things a strict parser rejects but Snowflake accepts — an over-escaped quote (\', whose backslash is dropped), invalid backslash escapes (e.g. a regex \d, whose backslash is kept literally), and finally a trailing comma or a raw control character inside a string.
    static String
    The unquoted text of a value that is a QUOTED JSON string ("...") — the form path extraction uses for string values whose content looks like JSON structure — or null when the value is anything else.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parse

      public static tools.jackson.databind.JsonNode parse(Object value)
    • parseLenient

      public static tools.jackson.databind.JsonNode parseLenient(String input)
      Parse JSON the way Snowflake tolerates it: strictly first, and on failure retry after relaxing the things a strict parser rejects but Snowflake accepts — an over-escaped quote (\', whose backslash is dropped), invalid backslash escapes (e.g. a regex \d, whose backslash is kept literally), and finally a trailing comma or a raw control character inside a string. Returns null if it still cannot be parsed.
    • quotedJsonStringText

      public static String quotedJsonStringText(Object value)
      The unquoted text of a value that is a QUOTED JSON string ("...") — the form path extraction uses for string values whose content looks like JSON structure — or null when the value is anything else. PARSE_JSON/TRY_PARSE_JSON and the VARCHAR cast use this so a variant string field holding JSON text round-trips to its raw text before parsing.
    • escapeInvalidBackslashes

      public static String escapeInvalidBackslashes(String s)
      DROP every backslash that does not begin a valid JSON escape (i.e. is not followed by one of the characters " \ / b f n r t u) — live-verified: Snowflake's PARSE_JSON turns "a\d+" into ad+, discarding the invalid backslash rather than keeping it. Valid escapes and already-escaped backslashes are left untouched.