jsonb_typeof() and json_typeof()

Purpose: Return the data type of the JSON value as a SQL text value.

Signature For the jsonb variant:

input value:       jsonb
return value:      text

Notes: Possible return values are string, number, boolean, null, object, and array, as follows.

do $body$
declare
  j_string   constant jsonb := '"dog"';
  j_number   constant jsonb := '42';
  j_boolean  constant jsonb := 'true';
  j_null     constant jsonb := 'null';
  j_object   constant jsonb := '{"a": 17, "b": "x", "c": true}';
  j_array    constant jsonb := '[17, "x", true]';
begin
  assert
    jsonb_typeof(j_string)   = 'string'  and
    jsonb_typeof(j_number)   = 'number'  and
    jsonb_typeof(j_boolean)  = 'boolean' and
    jsonb_typeof(j_null)     = 'null'    and
    jsonb_typeof(j_object)   = 'object'  and
    jsonb_typeof(j_array)    = 'array',
 'unexpected';
end;
$body$;