Looked through the docs, but didn't find an explanation of what exact purpose the $ is doing in the following lines of code:
Some code I found in our codebase:
set jsonData = JSON_ARRAY_APPEND(coalesce(jsonData, '[]'), '$',
JSON_OBJECT('name', 'facility_id', 'old_value', '', 'new_value', NEW.facility_id));
and some code found in MySql docs:
mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1);
Looked through the docs, but didn't find an explanation of what exact purpose the $ is doing in the following lines of code:
Some code I found in our codebase:
set jsonData = JSON_ARRAY_APPEND(coalesce(jsonData, '[]'), '$',
JSON_OBJECT('name', 'facility_id', 'old_value', '', 'new_value', NEW.facility_id));
and some code found in MySql docs:
mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1);
Share
Improve this question
edited Mar 21 at 13:57
Saba Iqbal
171 gold badge1 silver badge11 bronze badges
asked Mar 19 at 19:02
ZacharyZachary
12 bronze badges
1
- 3 JSON Path Syntax For paths used in MySQL JSON functions, the scope is always the document being searched or otherwise operated on, represented by a leading $ character. – Akina Commented Mar 19 at 19:33
1 Answer
Reset to default -1The $
symbol in MySQL JSON-related statements is used as a JSON path expression. JSON path expressions are used to specify the location of data within a JSON document. Here are the key details:
JSON Path Expression: The
$
symbol represents the root of the JSON document. It is used to navigate within the JSON structure.ex:
set jsonData = JSON_ARRAY_APPEND(coalesce(jsonData, '[]'), '$', JSON_OBJECT('name', 'facility_id', 'old_value', '', 'new_value', NEW.facility_id));
, -----> the$
symbol indicates that the new JSON object should be appended to the root array of thejsonData
.SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1);
, -----> the$[1]
specifies the second element in the root array of the JSON document stored in the variable@j
.For more info : MySQL JSON Functions Documentation