JSON

JSON_ARRAY_APPEND

MySQLMySQL

Appends one or more values to the end of an array within a JSON document. The path must point to an existing array.

Tipe hasil: JSONDiperbarui: 13 Jun 2026

Syntax

SQL
JSON_ARRAY_APPEND(json_doc, path, val[, path, val] ...)

Parameter

json_docJSONwajib

The source JSON document

pathVARCHARwajib

The path to the array to append to

valanywajib

The value to append to the array

Contoh Penggunaan

Append to Array

SQL
1SELECT JSON_ARRAY_APPEND('{"tags": ["a", "b"]}', '$.tags', 'c') AS result;

Append 'c' to the end of the tags array.

Hasil
{"tags": ["a", "b", "c"]}

Append Multiple Values

SQL
1SELECT JSON_ARRAY_APPEND('{"items": [1]}', '$.items', 2, '$.items', 3) AS result;

Append 2 and then 3 sequentially to the items array.

Hasil
{"items": [1, 2, 3]}

Add Tag to Product

SQL
1UPDATE products
2SET tags = JSON_ARRAY_APPEND(tags, '$', 'new-tag')
3WHERE id = 1;

Append a new tag to a product's tags array.

Hasil
(tag appended)

Pertanyaan Umum tentang JSON_ARRAY_APPEND

Apa itu fungsi JSON_ARRAY_APPEND di MySQL?
Appends one or more values to the end of an array within a JSON document. The path must point to an existing array. Di MySQL, fungsi JSON_ARRAY_APPEND termasuk dalam kelompok fungsi yang sering digunakan untuk mengolah dan menganalisis data secara efisien.
Bagaimana cara menggunakan JSON_ARRAY_APPEND di MySQL?
Gunakan sintaks berikut: JSON_ARRAY_APPEND(json_doc, path, val[, path, val] ...). Pastikan argumen yang dimasukkan sudah sesuai dengan tipe data yang diharapkan.
Apa nilai yang dikembalikan oleh fungsi JSON_ARRAY_APPEND?
Fungsi JSON_ARRAY_APPEND mengembalikan nilai bertipe JSON. Pastikan tipe data hasil sudah sesuai dengan kebutuhan query atau formula kamu. Jika input mengandung nilai NULL, perilaku fungsi dapat berbeda — selalu periksa dokumentasi untuk memastikan hasilnya sesuai ekspektasi.
Apa saja parameter fungsi JSON_ARRAY_APPEND?
Fungsi ini memiliki 3 parameter wajib. Parameter yang digunakan: json_doc (JSON, wajib): The source JSON document; path (VARCHAR, wajib): The path to the array to append to; val (any, wajib): The value to append to the array.
Ngulik Langsung

Sudah paham JSON_ARRAY_APPEND? Latih langsung di browser

Latihan interaktif, langsung di browser.

Latihan Langsung →