Class JsonDSL
- java.lang.Object
-
- com.github.t9t.jooq.json.JsonDSL
-
public final class JsonDSL extends Object
Functions for
jsonPostgreSQL operator support in jOOQReference: https://www.postgresql.org/docs/11/functions-json.html
-
-
Constructor Summary
Constructors Constructor Description JsonDSL()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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->operatorstatic org.jooq.Field<String>arrayElementText(org.jooq.Field<org.jooq.JSON> jsonField, int index)Get JSON array element astextrather thanjson(b)(indexed from zero, negative integers count from the end), using the->>operatorstatic 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, String... path)Returns JSON value pointed to bypath(equivalent to#>operator, ie.static org.jooq.Field<org.jooq.JSON>extractPath(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)Returns JSON value pointed to bypath(equivalent to#>operator, ie.static org.jooq.Field<String>extractPathText(org.jooq.Field<org.jooq.JSON> jsonField, String... path)Returns JSON value pointed to bypathas text (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 bypathas text (equivalent to#>>operator, ie.static org.jooq.Field<org.jooq.JSON>field(String json)Create a jOOQFieldwrapping aJSONobject representing ajsonvalue for the JSON string.static org.jooq.Field<org.jooq.JSON>field(org.jooq.JSON json)Create a jOOQFieldwrapping theJSONobject.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->operatorstatic org.jooq.Field<String>fieldByKeyText(org.jooq.Field<org.jooq.JSON> jsonField, String key)Get JSON object field astextrather thanjson(b), using the->>operatorstatic org.jooq.Field<org.jooq.JSON>objectAtPath(org.jooq.Field<org.jooq.JSON> jsonField, String... path)Get JSON object at specified path using the#>operatorstatic 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#>operatorstatic org.jooq.Field<String>objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField, String... path)Get JSON object at specified path astextrather thanjson(b), using the#>>operatorstatic org.jooq.Field<String>objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)Get JSON object at specified path astextrather thanjson(b), using the#>>operatorstatic org.jooq.Field<org.jooq.JSON>stripNulls(org.jooq.Field<org.jooq.JSON> jsonField)Returns a JSONFieldwith all object fields that havenullvalues 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.
-
-
-
Method Detail
-
field
public static org.jooq.Field<org.jooq.JSON> field(String json)
Create a jOOQFieldwrapping aJSONobject representing ajsonvalue for the JSON string. Note that the JSON is not validated (any formatting errors will only occur when interacting with the database).- Parameters:
json- JSON string- Returns:
jsonFieldfor the JSON string
-
field
public static org.jooq.Field<org.jooq.JSON> field(org.jooq.JSON json)
Create a jOOQFieldwrapping theJSONobject.- Parameters:
json-JSONobject to wrap- Returns:
jsonFieldfor theJSONobject
-
arrayElement
public 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
->operatorExample:
'[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->2Example result:
{"c":"baz"}- Parameters:
jsonField- A JSONFieldcontaining an array to get the array element fromindex- Array index; negative values count from the end- Returns:
- A
Fieldrepresenting the extracted array element
-
arrayElementText
public static org.jooq.Field<String> arrayElementText(org.jooq.Field<org.jooq.JSON> jsonField, int index)
Get JSON array element as
textrather thanjson(b)(indexed from zero, negative integers count from the end), using the->>operatorExample:
'[1,2,3]'::json->>2Example result:
3- Parameters:
jsonField- A JSONFieldcontaining an array to get the array element fromindex- Array index; negative values count from the end- Returns:
- A
Fieldrepresenting the extracted array element, as text
-
fieldByKey
public 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
->operatorExample:
'{"a": {"b":"foo"}}'::json->'a'Example result:
{"b":"foo"}- Parameters:
jsonField- The JSONFieldto extract the field fromkey- JSON field key name- Returns:
- A
Fieldrepresenting the extracted value
-
fieldByKeyText
public static org.jooq.Field<String> fieldByKeyText(org.jooq.Field<org.jooq.JSON> jsonField, String key)
Get JSON object field as
textrather thanjson(b), using the->>operatorExample:
'{"a":1,"b":2}'::json->>'b'Example result:
2- Parameters:
jsonField- The JSONFieldto extract the field fromkey- JSON field key name- Returns:
- A
Fieldrepresenting the extracted array element, as text
-
objectAtPath
public 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
#>operatorExample:
'{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}'Example result:
{"c": "foo"}- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path - See Also:
objectAtPath(Field, Collection)
-
objectAtPath
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
#>operatorExample:
'{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}'Example result:
{"c": "foo"}- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path - See Also:
objectAtPath(Field, String...)
-
objectAtPathText
public static org.jooq.Field<String> objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField, String... path)
Get JSON object at specified path as
textrather thanjson(b), using the#>>operatorExample:
'{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'Example result:
3- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path, as text - See Also:
objectAtPathText(Field, Collection)
-
objectAtPathText
public static org.jooq.Field<String> objectAtPathText(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)
Get JSON object at specified path as
textrather thanjson(b), using the#>>operatorExample:
'{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'Example result:
3- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path, as text - See Also:
objectAtPath(Field, String...)
-
arrayLength
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- Parameters:
jsonField- The JSONFieldcontaining an array to measure the length of- Returns:
- Length of the array
-
extractPath
public 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"}- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path - See Also:
objectAtPath(Field, String...),objectAtPath(Field, Collection),extractPath(Field, Collection)
-
extractPath
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"}- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path - See Also:
objectAtPath(Field, String...),objectAtPath(Field, Collection),extractPath(Field, String...)
-
extractPathText
public static org.jooq.Field<String> extractPathText(org.jooq.Field<org.jooq.JSON> jsonField, String... path)
Returns JSON value pointed to by
pathas 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- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path, as text - See Also:
objectAtPathText(Field, String...),objectAtPathText(Field, Collection),extractPathText(Field, Collection)
-
extractPathText
public static org.jooq.Field<String> extractPathText(org.jooq.Field<org.jooq.JSON> jsonField, Collection<String> path)
Returns JSON value pointed to by
pathas 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- Parameters:
jsonField- The JSONFieldto extract the path frompath- Path to the the object to return- Returns:
- A
Fieldrepresenting the object at the specified path, as text - See Also:
objectAtPathText(Field, String...),objectAtPathText(Field, Collection),extractPathText(Field, String...)
-
typeOf
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, andnull.Example:
json_typeof('-123.4')Example result:
number- Parameters:
jsonField- The JSONFieldto determine the type of- Returns:
- The JSON type
-
stripNulls
public static org.jooq.Field<org.jooq.JSON> stripNulls(org.jooq.Field<org.jooq.JSON> jsonField)
Returns a JSON
Fieldwith all object fields that havenullvalues omitted. Othernullvalues (eg. in arrays) are untouched.Example:
json_strip_nulls('[{"f1":1,"f2":null},2,null,3]')Example result:
[{"f1":1},2,null,3]- Parameters:
jsonField- The JSONFieldto removenullvalues from- Returns:
- A JSON
Fieldwithnullobject fields removed
-
-