JSON
MySQL
JSON_DEPTH
Mengembalikan kedalaman maksimum JSON document. Empty array/object = 1, scalar = 1, nested structures menambah depth.
Tipe hasil:
INTDiperbarui: 7 Jan 2026Syntax
SQL
JSON_DEPTH(json_doc)Parameter
json_docJSONwajib
JSON document
Contoh Penggunaan
Simple Array Depth
SQL
1 SELECT JSON_DEPTH('[1, 2, 3]') AS depth;
Array sederhana tanpa nesting.
Hasil
depth: 2
Nested Object Depth
SQL
1 SELECT JSON_DEPTH('{"a": {"b": {"c": 1}}}') AS depth;
Object dengan 3 level nesting.
Hasil
depth: 4
Find Deep JSON
SQL
1 SELECT id, JSON_DEPTH(data) AS depth 2 FROM json_table 3 WHERE JSON_DEPTH(data) > 5;
Mencari JSON dengan nesting dalam.
Hasil
(deeply nested JSON rows)