10 Kesalahan Umum Saat Menulis JSON dan Cara Memperbaikinya
- Trailing comma.
{"a":1, "b":2,}— koma setelah elemen terakhir tidak valid. Hapus koma sebelum kurung penutup. - Single quote.
{'a': 1}— JSON wajib pakai tanda kutip dua. Ganti semua'jadi". - Key tanpa kutip.
{a: 1}— beda dengan object literal JavaScript, key JSON harus selalu diapit"a". - Comment di dalam JSON.
// catatan— JSON murni tidak mendukung komentar sama sekali, hapus atau pindahkan ke dokumentasi terpisah. - NaN, undefined, atau function. Nilai-nilai ini valid di JavaScript tapi tidak valid di JSON. Gunakan
nullsebagai gantinya. - Encoding karakter spesial yang salah. Karakter seperti tab, newline, atau tanda kutip di dalam string harus di-escape:
\n,\t,\". - Duplicate key.
{"a":1, "a":2}— secara teknis bisa diparse oleh sebagian parser (akan ambil nilai terakhir), tapi sangat berisiko ambigu dan sebaiknya dihindari. - Angka dengan leading zero.
0123tidak valid sebagai number JSON. Kalau memang format seperti kode pos/kode area, simpan sebagai string:"0123". - Bracket/brace tidak seimbang. Kurang satu
}atau]sering jadi penyebab error "Unexpected end of JSON input" — biasanya terjadi pada struktur sangat nested. - BOM (Byte Order Mark) tersembunyi. File JSON yang disimpan dengan encoding tertentu kadang punya karakter BOM tak terlihat di awal file yang membuat parser gagal — simpan ulang sebagai UTF-8 tanpa BOM.
💡 Daripada mencari error satu-satu secara manual, paste JSON kamu ke JSONYAMify — tool akan menunjukkan baris bermasalah secara otomatis sekaligus menawarkan auto-fix untuk kesalahan format yang umum.
🔧 Validasi JSON Kamu Sekarang
10 Common JSON Mistakes and How to Fix Them
- Trailing comma.
{"a":1, "b":2,}— a comma after the last element is invalid. Remove it before the closing bracket. - Single quotes.
{'a': 1}— JSON requires double quotes. Replace every'with". - Unquoted keys.
{a: 1}— unlike JavaScript object literals, JSON keys must always be wrapped in"a". - Comments inside JSON.
// note— pure JSON has zero support for comments; remove them or move them to separate documentation. - NaN, undefined, or functions. These are valid in JavaScript but invalid in JSON. Use
nullinstead. - Incorrect special character encoding. Characters like tabs, newlines, or quotes inside strings must be escaped:
\n,\t,\". - Duplicate keys.
{"a":1, "a":2}— technically some parsers accept this (keeping the last value), but it's highly ambiguous and should be avoided. - Numbers with leading zeros.
0123is not a valid JSON number. If it's a format like a zip/area code, store it as a string instead:"0123". - Unbalanced brackets/braces. A missing
}or]is a common cause of "Unexpected end of JSON input" errors, especially in deeply nested structures. - Hidden BOM (Byte Order Mark). JSON files saved with certain encodings can carry an invisible BOM character at the start that breaks parsers — re-save as UTF-8 without BOM.
💡 Instead of hunting for errors manually, paste your JSON into JSONYAMify — it automatically points out the problem line and offers auto-fixes for common formatting mistakes.
🔧 Validate Your JSON Now