JSON
MySQL
JSON_SET
Menyisipkan atau mengganti nilai di JSON document. Insert jika path belum ada, replace jika sudah ada.
Tipe hasil:
JSONDiperbarui: 7 Jan 2026Syntax
SQL
JSON_SET(json_doc, path, val[, path, val] ...)Parameter
json_docJSONwajib
JSON document sumber
pathVARCHARwajib
Path untuk nilai
valanywajib
Nilai baru
Contoh Penggunaan
Set New Field
SQL
1 SELECT JSON_SET('{"name": "John"}', '$.age', 30) AS result;
Menambahkan field 'age' baru.
Hasil
{"name": "John", "age": 30}
Replace Existing Field
SQL
1 SELECT JSON_SET('{"name": "John"}', '$.name', 'Jane') AS result;
Mengganti nilai 'name' yang sudah ada.
Hasil
{"name": "Jane"}
Update Column
SQL
1 UPDATE users 2 SET profile = JSON_SET(profile, '$.updated_at', NOW()) 3 WHERE id = 1;
Update timestamp di JSON column.
Hasil
(profile updated with timestamp)