← Kembali ke Blog

Panduan JSON Beautifier 2026: Memformat dan Pretty Print JSON

Panduan lengkap JSON beautifier. Pelajari cara memformat, me-minify, dan me-pretty print JSON menggunakan alat online, baris perintah, dan kode.

Big JSON Team9 menit bacaalat
B

Big JSON Team

Technical Writer

Expert in JSON data manipulation, API development, and web technologies. Passionate about creating tools that make developers' lives easier.

9 min read

Apa itu JSON Beautifier?

JSON beautifier (juga disebut pemformat atau pretty printer) mengubah JSON yang ringkas menjadi format yang mudah dibaca dan memiliki indentasi.

Sebelum (Diminimalkan/Minified)

{"users":[{"name":"Alice","age":30},{"name":"Bob","age":25}]}

Sesudah (Dipercantik/Beautified)

{

"users": [

{

"name": "Alice",

"age": 30

},

{

"name": "Bob",

"age": 25

}

]

}

Mengapa Mempercantik (Beautify) JSON?

  • Keterbacaan - Struktur lebih mudah dipahami
  • Debugging - Menemukan kesalahan dengan cepat
  • Code Review - Perbandingan diff yang lebih baik
  • Dokumentasi - Contoh yang lebih jelas
  • Beautifier Online

    Big JSON Viewer

  • Buka bigjson.online
  • Tempel atau unggah JSON
  • Lihat output yang diformat
  • Salin atau unduh
  • Menangani file hingga 100MB+

    JSONLint

    Validator klasik dengan fitur pemformatan.

    Alat Baris Perintah (Command Line Tools)

    jq

    # Instalasi
    

    brew install jq # Mac

    apt install jq # Linux

    # Mempercantik (Beautify)

    jq '.' input.json > output.json

    # Indentasi kustom

    jq --indent 4 '.' input.json

    # Urutkan kunci

    jq -S '.' input.json

    Python

    # Modul bawaan
    

    python -m json.tool input.json

    # Indentasi kustom

    python -c "import json; print(json.dumps(json.load(open('input.json')), indent=4))"

    Pemformatan Editor Kode

    VS Code

    • Pintasan: Shift+Alt+F (Windows) atau Shift+Option+F (Mac)
    • Perintah: Ctrl+Shift+P → "Format Document"
    • Format otomatis saat simpan: Aktifkan di pengaturan (settings)

    Pempercantikan Programatik

    JavaScript

    const ugly = '{"name":"John","age":30}';
    

    const pretty = JSON.stringify(JSON.parse(ugly), null, 2);

    console.log(pretty);

    // Indentasi kustom (4 spasi)

    JSON.stringify(obj, null, 4);

    // Tab alih-alih spasi

    JSON.stringify(obj, null, '\t');

    Python

    import json
    
    

    ugly = '{"name":"John","age":30}'

    data = json.loads(ugly)

    pretty = json.dumps(data, indent=2)

    print(pretty)

    # Urutkan kunci

    json.dumps(data, indent=2, sort_keys=True)

    Minifikasi JSON

    Kebalikannya - menghapus spasi kosong untuk mengurangi ukuran file:

    // JavaScript
    

    const minified = JSON.stringify(obj);

    // jq

    jq -c '.' input.json

    Perbandingan Alat

    | Alat | Kecepatan | File Besar | Validasi | Gratis |

    |------|-------|-------------|------------|------|

    | Big JSON Viewer | Cepat | ✅ | ✅ | ✅ |

    | jq | Sangat Cepat | ✅ | ❌ | ✅ |

    | VS Code | Cepat | Sedang | ✅ | ✅ |

    | Python | Sedang | Sedang | ❌ | ✅ |

    Praktik Terbaik

  • Format sebelum melakukan commit ke kontrol versi
  • Gunakan indentasi yang konsisten (2 atau 4 spasi)
  • Konfigurasikan editor untuk memformat saat menyimpan (format on save)
  • Minifikasi untuk produksi untuk menghemat bandwidth
  • Opsi Pemformatan

    Gaya Indentasi

    • 2 spasi: Standar untuk pengembangan web
    • 4 spasi: Umum dalam proyek Python
    • Tab: Kurang umum, ukuran file lebih besar

    Pengurutan Kunci

    Kunci yang diurutkan secara alfabetis membuat diff lebih jelas:

    {
    

    "age": 30,

    "email": "alice@example.com",

    "name": "Alice"

    }

    Kesimpulan

    Untuk pemformatan cepat, gunakan Big JSON Viewer atau jq. Untuk pengeditan rutin, konfigurasikan editor Anda agar memformat secara otomatis saat menyimpan!

    Share:

    Artikel Terkait

    Read in English