Expand description
v4.14 minimal JSON parser for the -> / ->> operators.
Hand-rolled, no external dep — same policy as the rest of the
engine. Supports the JSON grammar from RFC 8259: objects,
arrays, strings (with \" / \\ / \/ / \b / \f / \n
/ \r / \t / \uXXXX escapes), numbers, true / false /
null. The parser returns a tree we walk by key (object) or
integer index (array); accesses that miss return Value::Null
per PG semantics.
path_get(doc, key, as_text) is the public entry. When
as_text is true (->> operator), JSON strings unwrap to
raw text and other scalars render as their canonical text;
when false (->), the result is wrapped back into a Json
value (the inner subtree rendered to its canonical JSON
string form).
Enums§
- Json
Value - Mysql
Path Step - v7.37.17 (17.6 siblings) — one step of a MySQL JSON path
(
$.key,$."quoted key",$[0]). - Parse
Error
Functions§
- array_
element_ rows - v7.37.17 (17.6 siblings) — set-returning function
jsonb_array_elements[_text](json). PG semantics: one row per array element._textrenders scalars as their lexeme and JSON null as SQL NULL; the plain form renders every element (including JSON null) as compact JSON text. Non-array inputs raise an error (PG’s actual behaviour); SQL NULL produces 0 rows. - build_
array json_build_array(...)— variadic; empty → “[]”. Each arg encoded viavalue_to_json_text.- build_
object - canonicalize_
jsonb - Canonicalise a jsonb text value the way PostgreSQL does on input:
object keys sorted by (length, then bytewise) with duplicate keys
collapsed last-wins,
,/:whitespace, and numbers normalised to plain decimal (exponents expanded,-0→0, but trailing zeros from the input scale preserved —1e2→100,1E-3→0.001,1.10stays1.10).jsonkeeps its input verbatim; onlyjsonbruns through this. - canonicalize_
value - concat
json_build_object(k, v, k, v, …)— variadic, even-length. NULL key → error (PG: “argument cannot be null”). Values encoded viavalue_to_json_text. Returns Value::Json. v7.37.17 (17.6 siblings) —jsonb_concat(a, b)— function form of the||operator. Object + object merges keys (right wins on duplicates); array + array appends; array + scalar appends the scalar; scalar + scalar makes a 2-element array (PG semantics).- contains
- delete_
key - v7.37.17 (17.6 siblings) —
jsonb_delete(doc, key)— function form of the-operator. Removes an object key or an array element (by text match for objects, by index for arrays). - delete_
path - v7.37.17 (17.6 siblings) —
jsonb_delete_path(doc, path[])— function form of the#-operator. Removes the value at the nested path; missing path leaves the doc unchanged. - each_
rows - v7.37.17 (17.6 siblings) — shared body for the four
eachSRFs.as_text(the*_each_textforms) unwraps scalar values to their lexeme and maps JSON null → SQL NULL; the plain forms render every value (including JSON null) as compact JSON text, which the executor wraps as a jsonb-typed column. - equals
jsonb = jsonbstructural equality (PG18-compatible). PG’s jsonb equality is order-INDEPENDENT for object keys but order-SENSITIVE for array elements, and it compares numbers by value (so'1'::jsonb = '1.0'::jsonbis true).json_eqencodes those rules; this parses both operands and delegates. Values reaching here through the::jsonbcast / a jsonb column are already canonicalised (keys sorted, duplicates collapsed), so object equality is exact.- insert
jsonb_insert(target, path, new_value [, insert_after])— insert at path.insert_afterdefaults to false.- jsonb_
compare - v7.38 (read01 P6.24) — PG’s
jsonbtotal order (ORDER BY / DISTINCT / btree). First by type rankNull < String < Number < Boolean < Array < Object; then within a type: strings by content, numbers numerically, booleansfalse < true, arrays by length then element-wise, objects by pair-count then key/value pairwise (keys in canonical stored order). Mirrors the observable behaviour ofjsonb.c’scompareJsonbContainers. - jsonb_
each_ text_ rows - v6.4.5 — PG
json #> path_text/json #>> path_text. The right-hand side is a PG text-array literal'{a,0,b}'whose elements are walked left-to-right; each element is either an object key or (when it parses as a non-negative integer) an v7.37.43-T4.5 — set-returning functionjsonb_each_text(jsonb). PG semantics: for each (key, value) pair in the object, emit one row whosekeycolumn is the literal key andvaluecolumn is the JSON value rendered as text (null→ SQL NULL, primitives → their lexeme, nested objects/arrays → JSON text). - jsonpath_
canonical - Encode a Value as its canonical JSON text (no surrounding quotes for non-strings). Used by every builder below.
- key_
exists - v6.4.5 — PG
json @> sub_jsoncontainment. Returns BOOL.lhs @> rhsis true when every member ofrhsis structurally contained inlhs: - keys_
all - v7.37.6-A — PG
jsonb ?& text[]. Returns BOOL: true iff every one of the listed keys exists at the top level. - keys_
any - v7.37.6-A — PG
jsonb ?| text[]. Returns BOOL: true iff any one of the listed keys exists at the top level. - mysql_
json_ array_ append - v7.37.17 (17.6 siblings) — MySQL JSON_ARRAY_APPEND(doc, path,
val, …). The value at path gains
valat the end; a non-array value wraps as[old, val](MySQL semantics). - mysql_
json_ array_ insert - v7.37.17 (17.6 siblings) — MySQL JSON_ARRAY_INSERT(doc, path,
val, …). The path must end in
[N]; the value is inserted at position N in the parent array, shifting later elements right (past-the-end appends). A non-array parent is a no-op. - mysql_
json_ contains - v7.37.17 (17.6 siblings) — MySQL JSON_CONTAINS(target, candidate [, path]).
- mysql_
json_ contains_ path - v7.37.17 (17.6 siblings) — MySQL JSON_CONTAINS_PATH(doc, ‘one’|‘all’, path…).
- mysql_
json_ extract - v7.37.17 (17.6 siblings) — MySQL JSON_EXTRACT(doc, path…). One path → the value at that path (or SQL NULL when it misses); several paths → a JSON array of the values that matched (NULL when none did).
- mysql_
json_ insert - mysql_
json_ merge_ patch - v7.37.17 (17.6 siblings) — MySQL JSON_MERGE_PATCH (RFC 7396).
- mysql_
json_ merge_ preserve - v7.37.17 (17.6 siblings) — MySQL JSON_MERGE_PRESERVE (and its deprecated JSON_MERGE alias).
- mysql_
json_ overlaps - v7.37.17 (17.6 siblings) — MySQL JSON_OVERLAPS(d1, d2): arrays share any element; objects share any key-value pair; scalars compare equal; an array vs a scalar checks membership.
- mysql_
json_ remove - v7.37.17 (17.6 siblings) — MySQL JSON_REMOVE(doc, path…).
Removing the root path
$errors, as in MySQL. - mysql_
json_ replace - mysql_
json_ search - v7.37.17 (17.6 siblings) — MySQL JSON_SEARCH(doc, ‘one’|‘all’, pattern [, escape [, path…]]). Returns the path of the first string value LIKE-matching the pattern (‘one’) or a JSON array of all such paths (‘all’); NULL when nothing matches. The optional path args narrow where the walk starts.
- mysql_
json_ set - v7.37.17 (17.6 siblings) — MySQL JSON_SET / JSON_INSERT / JSON_REPLACE (‘$.x’-path forms; the PG jsonb_set text-array spelling stays on crate::json::set).
- mysql_
json_ value - v7.37.17 (17.6 siblings) — MySQL JSON_VALUE(doc, path). Returns the scalar at the path as unquoted text (MySQL’s default RETURNING VARCHAR); containers render as JSON text; a miss is NULL. The RETURNING clause is parser syntax and queued.
- mysql_
path_ get - Walk a parsed JSON document along a MySQL path. Returns None when any step misses.
- mysql_
path_ steps - Parse a MySQL JSON path. Supports
$,.key,."quoted key"and[N]; wildcard steps (*,[*],**) error honestly — they return multiple matches per document and need a different walker shape. - parse
- parse_
path_ vars - v7.39 — parse the
varsargument of the jsonb_path_* family into a JsonValue object (NULL → no vars). - path_
get - PG
json -> key/json ->> key.lhsmust be JSON or TEXT containing JSON.rhsis either a TEXT key (object access) or an INT index (array access).as_text=truefor->>(returnsValue::Text);falsefor->(returnsValue::Json). - path_
predicate - v7.38 (read01, T8) — evaluate a top-level jsonpath boolean predicate like
$.a > 3(the form the@@operator / jsonb_path_match takes). ReturnsSome(bool)when the path is a top-level comparison, orNoneto let the caller fall back to the ordinary path-query match ($.a ? (...)etc.). - path_
predicate_ vars - v7.39 —
path_predicatewith a jsonbvarsdocument. - path_
query - v7.17.0 Phase 3.9 —
jsonb_path_query(doc, path)— returns the matched JSON values as a TextArray (each element is the JSON encoding of one match). - path_
query_ array - v7.17.0 Phase 3.9 —
jsonb_path_query_array(doc, path)returns the matched values wrapped as a single JSON array. - path_
query_ array_ vars - v7.39 —
path_query_arraywith a jsonbvarsdocument. - path_
query_ first - v7.17.0 Phase 3.9 —
jsonb_path_query_first(doc, path)returns the first matched JSON value as a Json, or NULL on no match. - path_
query_ first_ vars - v7.39 —
path_query_firstwith a jsonbvarsdocument. - path_
query_ vars - v7.39 —
path_querywith a jsonbvarsdocument ($name references). - path_
walk - array index. Missing or non-existent steps return
Value::Null. - set
jsonb_set(target, path, new_value [, create_missing])— replace at PG text-array path.create_missingdefaults to true.- value_
to_ json_ text