public final class JsonDSL extends Object
Functions for json
PostgreSQL operator support in jOOQ
Reference: https://www.postgresql.org/docs/11/functions-json.html
Constructor and Description |
---|
JsonDSL() |
Modifier and Type | Method and Description |
---|---|
static org.jooq.Field<org.jooq.JSON> |
arrayElement(org.jooq.Field<org.jooq.JSON> jsonField,
int index)
Get JSON array element (indexed from zero, negative integers count from the end), using the
-> operator |
static org.jooq.Field<String> |
arrayElementText(org.jooq.Field<org.jooq.JSON> jsonField,
int index)
Get JSON array element as
text rather than json(b) (indexed from zero, negative integers
count from the end), using the ->> operator |
static org.jooq.Field<Integer> |
arrayLength(org.jooq.Field<org.jooq.JSON> jsonField)
Returns the number of elements in the outermost JSON array.
|
static org.jooq.Field<org.jooq.JSON> |
extractPath(org.jooq.Field<org.jooq.JSON> jsonField,
Collection<String> path)
Returns JSON value pointed to by
path (equivalent to #> operator, ie. |
static org.jooq.Field<org.jooq.JSON> |
extractPath(org.jooq.Field<org.jooq.JSON> jsonField,
String... path)
Returns JSON value pointed to by
path (equivalent to #> operator, ie. |
static org.jooq.Field<String> |
extractPathText(org.jooq.Field<org.jooq.JSON> jsonField,
Collection<String> path)
Returns JSON value pointed to by
path as text (equivalent to #>> operator, ie. |
static org.jooq.Field<String> |
extractPathText(org.jooq.Field<org.jooq.JSON> jsonField,
String... path)
Returns JSON value pointed to by
path as text (equivalent to #>> operator, ie. |
static org.jooq.Field<org.jooq.JSON> |
field(org.jooq.JSON json)
Create a jOOQ
Field wrapping the JSON object. |
static org.jooq.Field<org.jooq.JSON> |
field(String json)
Create a jOOQ
Field wrapping a JSON object representing a json value for the JSON
string. |
static org.jooq.Field<org.jooq.JSON> |
fieldByKey(org.jooq.Field<org.jooq.JSON> jsonField,
String key)
Get JSON object field by key using the
-> operator |
static org.jooq.Field<String> |
fieldByKeyText(org.jooq.Field<org.jooq.JSON> jsonField,
String key)
Get JSON object field as
text rather than json(b) , using the ->>
operator |
static org.jooq.Field<org.jooq.JSON> |
objectAtPath(org.jooq.Field<org.jooq.JSON> jsonField,
Collection<String> path)
Get JSON object at specified path using the
#> operator |
static org.jooq.Field<org.jooq.JSON> |
objectAtPath(org.jooq.Field<org.jooq.JSON> jsonField,
String... path)
Get JSON object at specified path using the
#> operator |
static org.jooq.Field<String> |
objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField,
Collection<String> path)
Get JSON object at specified path as
text rather than json(b) , using the #>>
operator |
static org.jooq.Field<String> |
objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField,
String... path)
Get JSON object at specified path as
text rather than json(b) , using the #>>
operator |
static org.jooq.Field<org.jooq.JSON> |
stripNulls(org.jooq.Field<org.jooq.JSON> jsonField)
Returns a JSON
Field with all object fields that have null values omitted. |
static org.jooq.Field<String> |
typeOf(org.jooq.Field<org.jooq.JSON> jsonField)
Returns the type of the outermost JSON value as a text string.
|
public static org.jooq.Field<org.jooq.JSON> field(String json)
Field
wrapping a JSON
object representing a json
value for the JSON
string. Note that the JSON is not validated (any formatting errors will only occur when
interacting with the database).json
- JSON stringjson
Field
for the JSON stringpublic static org.jooq.Field<org.jooq.JSON> field(org.jooq.JSON json)
Field
wrapping the JSON
object.json
- JSON
object to wrapjson
Field
for the JSON
objectpublic static org.jooq.Field<org.jooq.JSON> arrayElement(org.jooq.Field<org.jooq.JSON> jsonField, int index)
Get JSON array element (indexed from zero, negative integers count from the end), using the
->
operator
Example: '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->2
Example result: {"c":"baz"}
jsonField
- A JSON Field
containing an array to get the array element fromindex
- Array index; negative values count from the endField
representing the extracted array elementpublic static org.jooq.Field<String> arrayElementText(org.jooq.Field<org.jooq.JSON> jsonField, int index)
Get JSON array element as text
rather than json(b)
(indexed from zero, negative integers
count from the end), using the ->>
operator
Example: '[1,2,3]'::json->>2
Example result: 3
jsonField
- A JSON Field
containing an array to get the array element fromindex
- Array index; negative values count from the endField
representing the extracted array element, as textpublic static org.jooq.Field<org.jooq.JSON> fieldByKey(org.jooq.Field<org.jooq.JSON> jsonField, String key)
Get JSON object field by key using the ->
operator
Example: '{"a": {"b":"foo"}}'::json->'a'
Example result: {"b":"foo"}
jsonField
- The JSON Field
to extract the field fromkey
- JSON field key nameField
representing the extracted valuepublic static org.jooq.Field<String> fieldByKeyText(org.jooq.Field<org.jooq.JSON> jsonField, String key)
Get JSON object field as text
rather than json(b)
, using the ->>
operator
Example: '{"a":1,"b":2}'::json->>'b'
Example result: 2
jsonField
- The JSON Field
to extract the field fromkey
- JSON field key nameField
representing the extracted array element, as textpublic static org.jooq.Field<org.jooq.JSON> objectAtPath(org.jooq.Field<org.jooq.JSON> jsonField, String... path)
Get JSON object at specified path using the #>
operator
Example: '{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}'
Example result: {"c": "foo"}
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified pathobjectAtPath(Field, Collection)
public static org.jooq.Field<org.jooq.JSON> objectAtPath(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)
Get JSON object at specified path using the #>
operator
Example: '{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}'
Example result: {"c": "foo"}
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified pathobjectAtPath(Field, String...)
public static org.jooq.Field<String> objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField, String... path)
Get JSON object at specified path as text
rather than json(b)
, using the #>>
operator
Example: '{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'
Example result: 3
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified path, as textobjectAtPathText(Field, Collection)
public static org.jooq.Field<String> objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)
Get JSON object at specified path as text
rather than json(b)
, using the #>>
operator
Example: '{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'
Example result: 3
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified path, as textobjectAtPath(Field, String...)
public static org.jooq.Field<Integer> arrayLength(org.jooq.Field<org.jooq.JSON> jsonField)
Returns the number of elements in the outermost JSON array.
Example: json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]')
Example result: 5
jsonField
- The JSON Field
containing an array to measure the length ofpublic static org.jooq.Field<org.jooq.JSON> extractPath(org.jooq.Field<org.jooq.JSON> jsonField, String... path)
Returns JSON value pointed to by path
(equivalent to #>
operator, ie.
objectAtPath(Field, String...)
).
Example: json_extract_path('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4')
Example result: {"f5":99,"f6":"foo"}
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified pathobjectAtPath(Field, String...)
,
objectAtPath(Field, Collection)
,
extractPath(Field, Collection)
public static org.jooq.Field<org.jooq.JSON> extractPath(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)
Returns JSON value pointed to by path
(equivalent to #>
operator, ie.
objectAtPath(Field, Collection)
).
Example: json_extract_path('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4')
Example result: {"f5":99,"f6":"foo"}
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified pathobjectAtPath(Field, String...)
,
objectAtPath(Field, Collection)
,
extractPath(Field, String...)
public static org.jooq.Field<String> extractPathText(org.jooq.Field<org.jooq.JSON> jsonField, String... path)
Returns JSON value pointed to by path
as text (equivalent to #>>
operator, ie.
objectAtPathText(Field, String...)
).
Example: json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4', 'f6')
Example result: foo
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified path, as textobjectAtPathText(Field, String...)
,
objectAtPathText(Field, Collection)
,
extractPathText(Field, Collection)
public static org.jooq.Field<String> extractPathText(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)
Returns JSON value pointed to by path
as text (equivalent to #>>
operator, ie.
objectAtPathText(Field, Collection)
).
Example: json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}','f4', 'f6')
Example result: foo
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified path, as textobjectAtPathText(Field, String...)
,
objectAtPathText(Field, Collection)
,
extractPathText(Field, String...)
public static org.jooq.Field<String> typeOf(org.jooq.Field<org.jooq.JSON> jsonField)
Returns the type of the outermost JSON value as a text string. Possible types are object
, array
,
string
, number
, boolean
, and null
.
Example: json_typeof('-123.4')
Example result: number
jsonField
- The JSON Field
to determine the type ofpublic static org.jooq.Field<org.jooq.JSON> stripNulls(org.jooq.Field<org.jooq.JSON> jsonField)
Returns a JSON Field
with all object fields that have null
values omitted. Other null
values (eg. in arrays) are untouched.
Example: json_strip_nulls('[{"f1":1,"f2":null},2,null,3]')
Example result: [{"f1":1},2,null,3]
jsonField
- The JSON Field
to remove null
values fromField
with null
object fields removedCopyright © 2021. All rights reserved.