Class JsonExtract

java.lang.Object
io.trino.operator.scalar.JsonExtract

public final class JsonExtract extends Object
Extracts values from JSON

Supports the following JSON path primitives:

    $ : Root object
    . or [] : Child operator
   [] : Subscript operator for array
 

Supported JSON Path Examples:

    { "store": {
        "book": [
          { "category": "reference",
            "author": "Nigel Rees",
            "title": "Sayings of the Century",
            "price": 8.95,
            "contributors": [["Adam", "Levine"], ["Bob", "Strong"]]
          },
          { "category": "fiction",
            "author": "Evelyn Waugh",
            "title": "Sword of Honour",
            "price": 12.99,
            "isbn": "0-553-21311-3",
            "last_owner": null
          }
        ],
        "bicycle": {
          "color": "red",
          "price": 19.95
        }
      }
    }
 

With only scalar values using dot-notation of path:

    $.store.book[0].author => Nigel Rees
    $.store.bicycle.price => 19.95
    $.store.book[0].isbn => NULL (Doesn't exist becomes java null)
    $.store.book[1].last_owner => NULL (json null becomes java null)
    $.store.book[0].contributors[0][1] => Levine
 

With json values using dot-notation of path:

    $.store.book[0].author => "Nigel Rees"
    $.store.bicycle.price => 19.95
    $.store.book[0].isbn => NULL (Doesn't exist becomes java null)
    $.store.book[1].last_owner => null (json null becomes the string "null")
    $.store.book[0].contributors[0] => ["Adam", "Levine"]
    $.store.bicycle => {"color": "red", "price": 19.95}
 
With only scalar values using bracket-notation of path:
    $["store"]["book"][0]["author"] => Nigel Rees
    $["store"]["bicycle"]["price"] => 19.95
    $["store"]["book"][0]["isbn"] => NULL (Doesn't exist becomes java null)
    $["store"]["book"][1]["last_owner"] => NULL (json null becomes java null)
    $["store"]["book"][0]["contributors"][0][1] => Levine
 

With json values using bracket-notation of path:

    $["store"]["book"][0]["author"] => "Nigel Rees"
    $["store"]["bicycle"]["price"] => 19.95
    $["store"]["book"][0]["isbn"] => NULL (Doesn't exist becomes java null)
    $["store"]["book"][1]["last_owner"] => null (json null becomes the string "null")
    $["store"]["book"][0]["contributors"][0] => ["Adam", "Levine"]
    $["store"]["bicycle"] => {"color": "red", "price": 19.95}