JSON Functions & Operators

These apply to MonetDB SQL type: JSON (JavaScript Object Notation).

Note: All JSON functions are located in the json schema. You must include the json. prefix for all these functions in order to work properly.

FunctionReturn typeDescriptionExampleResult
json.filter(js, indx)jsonextracts a indexed component from js. The index starts at 0 for the first element.json.filter(json '["a", 4]', 1)[4]
json.filter(js, pathexpr)jsonextracts the compgonent from js that satisfied the pathexpr string. The supported JSON path expression syntax is documented at JSONPathjson.filter(json '{"price":9}', '$..price')[9]
json."integer"(js)bigint or int or smallint or tinyintturn a number or singleton array value or singleton object element of js into an integer. Returns null if it fails.json."integer"(json '{"n":4}')4
json.isarray(str)booleanchecks the string str for JSON array compliancejson.isarray('[1,7]')true
json.isarray(js)booleanchecks the JSON value js for JSON array compliancejson.isarray(json '[1,7]')true
json.isobject(str)booleanchecks the string str for JSON object compliancejson.isobject('{"n":4}')true
json.isobject(js)booleanchecks the JSON value js for JSON object compliancejson.isobject(json '{"n":4}')true
json.isvalid(str)booleanchecks the string str for JSON syntax compliancejson.isvalid('{"a":[1]}')true
json.isvalid(js)booleanchecks the JSON value js for JSON validityjson.isvalid(json '{"a":[1,2]}')true
json.keyarray(js)jsonreturns an arraylist of key tags for the top-level components of js. Note js must represent a JSON object else an error (Object expected) is reportedjson.keyarray(json '{"id":2, "nm":"X"}')["id","nm"]
json.length(js)intreturns the number of top-level components of jsjson.length(json '{"a":[1]}')1
json.number(js)doubleturn a number or singleton array value or singleton object tag of js into a double. Returns null if it fails.json.number(json '{"n":4}')4.0
json.text(js)clobglue together the values in js separated by space characterjson.text(json '[1,2,3,4]')1 2 3 4
json.text(js, Separator str)clobglue together the values in js separated by Separator stringjson.text(json '[1,2,3,4]', 'x')1x2x3x4
json.valuearray(js)jsonreturns an arraylist of value tags for the top-level components of js. Note js must represent a JSON object else an error (Object expected) is reportedjson.valuearray(json '{"a":1, "b":2}')[1,2]

Aggregate functions

They return a concatenated CLOB string which is a valid json array

FunctionReturn typeDescriptionExampleResult
json.tojsonarray(double)clobconvert numeric values in the column/group into a json array stringjson.tojsonarray(i)[ "1", "2", "3", "4" ]
json.tojsonarray(clob)clobconvert string values in the column/group into a json array stringjson.tojsonarray(c)[ "one", "two", "tree", "four" ]