JSON support

The JSON atomic type is a subtype of String. The module ensures that all strings are valid JSON. The module uses its own JSON parser.

The operations are exported into the SQL layer.

MODULE json;

PATTERN json.dump(X_0:json):bat[:str];
COMMENT "";

COMMAND json.filter(X_0:json, X_1:str):json;
COMMENT "Filter all members of an object by a path expression, returning an array.\nNon-matching elements are skipped.";

COMMAND json.filter(X_0:json, X_1:bte, X_2:str):json;
COMMENT "";

COMMAND json.filter(X_0:json, X_1:int, X_2:str):json;
COMMENT "";

COMMAND json.filter(X_0:json, X_1:lng, X_2:str):json;
COMMENT "Extract a single array element";

COMMAND json.filter(X_0:json, X_1:sht, X_2:str):json;
COMMENT "";

COMMAND json.filter(X_0:json, X_1:bte):json;
COMMENT "";

COMMAND json.filter(X_0:json, X_1:int):json;
COMMENT "";

COMMAND json.filter(X_0:json, X_1:lng):json;
COMMENT "";

COMMAND json.filter(X_0:json, X_1:sht):json;
COMMENT "";

PATTERN json.fold(X_0:bat[:any]):json;
COMMENT "Combine the value list into a single json array object.";

PATTERN json.fold(X_0:bat[:oid], X_1:bat[:str], X_2:bat[:any]):json;
COMMENT "Combine the key-value pairs into a single json object list.";

PATTERN json.fold(X_0:bat[:str], X_1:bat[:any]):json;
COMMENT "Combine the key-value pairs into a single json object list.";

COMMAND json.integer(X_0:json):lng;
COMMENT "Convert simple JSON values to an integer, return nil upon error.";

COMMAND json.isarray(X_0:json):bit;
COMMENT "Validate the string as a valid JSON array";

COMMAND json.isobject(X_0:json):bit;
COMMENT "Validate the string as a valid JSON object";

COMMAND json.isvalid(X_0:str):bit;
COMMENT "Validate the string as a valid JSON document";

COMMAND json.keyarray(X_0:json):json;
COMMENT "Expands the outermost JSON object keys into a JSON value array.";

COMMAND json.keys(X_0:json):bat[:str];
COMMENT "Expands the outermost JSON object names.";

COMMAND json.length(X_0:json):int;
COMMENT "Returns the number of elements in the outermost JSON object.";

COMMAND json.new(X_0:str):json;
COMMENT "Convert string to its JSON. Dealing with escape characters";

COMMAND json.number(X_0:json):dbl;
COMMENT "Convert simple JSON values to a double, return nil upon error.";

PATTERN json.renderarray(X_0:any...):json;
COMMENT "";

PATTERN json.renderobject(X_0:any...):json;
COMMENT "";

COMMAND json.resultSet(X_0:bat[:uuid], X_1:bat[:lng], X_2:bat[:json]):json;
COMMENT "Converts the json store into a single json string:";

COMMAND json.str(X_0:json):str;
COMMENT "Convert JSON to its string equivalent. Dealing with escape characters";

COMMAND json.text(X_0:json):str;
COMMENT "Convert JSON values to their plain string equivalent.";

COMMAND json.text(X_0:json, X_1:str):str;
COMMENT "Convert JSON values to their plain string equivalent, injecting a separator.";

PATTERN json.unfold(X_0:json) (X_1:bat[:oid], X_2:bat[:str], X_3:bat[:json]);
COMMENT "Expands the outermost JSON object into key-value pairs.";

PATTERN json.unfold(X_0:json) (X_1:bat[:str], X_2:bat[:json]);
COMMENT "Expands the outermost JSON object into key-value pairs.";

COMMAND json.valuearray(X_0:json):json;
COMMENT "Expands the outermost JSON object values into a JSON value array.";

COMMAND json.values(X_0:json):bat[:json];
COMMENT "Expands the outermost JSON values.";