Pre-General Availability Draft: 2017-07-17
Many of the functions described in previous sections require a
path expression in order to identify a specific element in a JSON
document. A path consists of the path's scope followed by one
or more path legs. For paths used in MySQL JSON functions, the
scope is always the document being searched or otherwise operated
on, represented by a leading $ character. Path
legs are separated by period characters (.).
Cells in arrays are represented by
[, where
N]N is a non-negative integer. Names of
keys must be double-quoted strings or valid ECMAScript identifiers
(see
http://www.ecma-international.org/ecma-262/5.1/#sec-7.6).
Path expressions, like JSON text, should be encoded using the
ascii, utf8, or
utf8mb4 character sets. Other character
encodings are implicitly coerced to utf8mb4.
The complete syntax is shown here:
pathExpression:
scope[(pathLeg)*]
pathLeg:
member | arrayLocation | doubleAsterisk
member:
period ( keyName | asterisk )
arrayLocation:
leftBracket ( nonNegativeInteger | asterisk ) rightBracket
keyName:
ESIdentifier | doubleQuotedString
doubleAsterisk:
'**'
period:
'.'
asterisk:
'*'
leftBracket:
'['
rightBracket:
']'
As noted previously, in MySQL, the scope of the path is always the
document being operated on, represented as $.
You can use '$' as a synonynm for the document
in JSON path expressions.
Some implementations support column references for scopes of JSON paths; currently, MySQL does not support these.
The wildcard * and ** tokens
are used as follows:
.*represents the values of all members in the object.[*]represents the values of all cells in the array.[represents all paths beginning withprefix]**suffixprefixand ending withsuffix.prefixis optional, whilesuffixis required; in other words, a path may not end in**.In addition, a path may not contain the sequence
***.
For path syntax examples, see the descriptions of the various JSON
fuinctions that take paths as arguments, such as
JSON_CONTAINS_PATH(),
JSON_SET(), and
JSON_REPLACE(). For examples which
include the use of the * and
** wildcards, see the description of the
JSON_SEARCH() function.