Package io.trino.operator.scalar
Class JsonExtract
java.lang.Object
io.trino.operator.scalar.JsonExtract
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}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classstatic classstatic classstatic class -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Textract(io.airlift.slice.Slice jsonInput, JsonExtract.JsonExtractor<T> jsonExtractor) static <T> JsonExtract.JsonExtractor<T> generateExtractor(String path, JsonExtract.JsonExtractor<T> rootExtractor) static <T> JsonExtract.JsonExtractor<T> generateExtractor(String path, JsonExtract.JsonExtractor<T> rootExtractor, boolean exceptionOnOutOfBounds)
-
Method Details
-
extract
public static <T> T extract(io.airlift.slice.Slice jsonInput, JsonExtract.JsonExtractor<T> jsonExtractor) -
generateExtractor
public static <T> JsonExtract.JsonExtractor<T> generateExtractor(String path, JsonExtract.JsonExtractor<T> rootExtractor) -
generateExtractor
public static <T> JsonExtract.JsonExtractor<T> generateExtractor(String path, JsonExtract.JsonExtractor<T> rootExtractor, boolean exceptionOnOutOfBounds)
-