Package io.prestosql.operator.scalar
Class JsonExtract
- java.lang.Object
-
- io.prestosql.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}
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JsonExtract.JsonExtractor<T>
static class
JsonExtract.JsonSizeExtractor
static class
JsonExtract.JsonValueJsonExtractor
static class
JsonExtract.ObjectFieldJsonExtractor<T>
static class
JsonExtract.ScalarValueJsonExtractor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
extract(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 Detail
-
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)
-
-