Class JsonKeywords

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

public final class JsonKeywords extends Object
The BARE WORDS a JSON document may carry, and the one thing that tells them apart: a word with a COLON after it is an attribute NAME, and any other word is a KEYWORD.

Live-verified. An unquoted NAME is a plain ASCII identifier — [A-Za-z_][A-Za-z0-9_]* — and nothing wider. {a:1}, {_:1}, {a_b:1} and {a1b:1} are read and the case is kept; a leading digit, a $, a @, a / and any non-ASCII letter are all refused. That narrowness is the whole reason the reader does this itself: Jackson's unquoted-name rule follows JavaScript identifiers, so it would also read {$a$:1}, which Snowflake REFUSES — and accepting a document live rejects is the worse of the two errors.

A word in NAME position is a name whatever it spells, so {true:1}, {null:1} and {nan:1} are objects with those attribute names rather than keywords.

Everywhere else a word is a KEYWORD, matched CASE-INSENSITIVELY (TRUE, tRuE, NAN, Inf …):

   true / false   -> BOOLEAN            null      -> the JSON null
   undefined      -> the undefined      nan       -> DOUBLE NaN
   inf / infinity -> DOUBLE Infinity
 

A SIGN may lead the non-finite words — -inf and -Infinity are negative, +inf and +NaN positive — with one asymmetry that is measured rather than reasoned: +NaN is read and -NaN is refused. Nothing else is a keyword, so infin, Infinit and None keep the unknown keyword "X", pos N refusal, at the word as written.

Neither NaN nor an infinity has a BigDecimal, and the reader builds BigDecimal for floats so a NUMBER(38,0) survives. So rather than relaxing the parser, the non-finite words are rewritten to a placeholder before parsing and restore(JsonNode) turns each one into its double afterwards — the same route the bare undefined token already takes. Names are quoted in the same pass, which also keeps a name out of the keyword rules: {nan:1} is quoted before anything looks for a keyword, so the placeholder can never end up as an attribute name.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Whether this parsed tree may still hold a placeholder, read off the text handed to the parser.
    static String
    The document with every keyword written the one way the parser reads it: the canonical words folded to lower case in place, and each non-finite word replaced by its placeholder.
    static tools.jackson.databind.JsonNode
    restore(tools.jackson.databind.JsonNode node)
    Turns every placeholder left by normalize(String) into the double it stands for.

    Methods inherited from class java.lang.Object

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

    • normalize

      public static String normalize(String text)
      The document with every keyword written the one way the parser reads it: the canonical words folded to lower case in place, and each non-finite word replaced by its placeholder. Text whose keywords are already canonical is returned unchanged.
    • mayHoldPlaceholder

      public static boolean mayHoldPlaceholder(String parsedText)
      Whether this parsed tree may still hold a placeholder, read off the text handed to the parser. The text carries the delimiter ESCAPED — six characters, not the NUL itself, which only appears once the parser has read the string literal.
    • restore

      public static tools.jackson.databind.JsonNode restore(tools.jackson.databind.JsonNode node)
      Turns every placeholder left by normalize(String) into the double it stands for.