JSON

JSON_MERGE_PATCH

MySQLMySQL

Menggabungkan JSON documents dengan RFC 7396 merge patch semantics. NULL values menghapus keys.

Tipe hasil: JSONDiperbarui: 7 Jan 2026

Syntax

SQL
JSON_MERGE_PATCH(json_doc, json_doc[, json_doc] ...)

Parameter

json_docJSONwajib

JSON documents untuk digabung

Contoh Penggunaan

Merge Two Objects

SQL
1SELECT JSON_MERGE_PATCH('{"name": "John"}', '{"age": 30}') AS result;

Gabungkan dua objects.

Hasil
{"name": "John", "age": 30}

Override Values

SQL
1SELECT JSON_MERGE_PATCH('{"a": 1, "b": 2}', '{"b": 10}') AS result;

Nilai b ditimpa oleh dokumen kedua.

Hasil
{"a": 1, "b": 10}

Remove with NULL

SQL
1SELECT JSON_MERGE_PATCH('{"name": "John", "temp": 1}', '{"temp": null}') AS result;

NULL menghapus key 'temp'.

Hasil
{"name": "John"}