JSONPath Tester
Uji ekspresi JSONPath terhadap data JSON.
Tentang alat ini
JSONPath adalah bahasa kueri untuk data JSON, mirip dengan XPath untuk XML. Alat Pengujian JSONPath membantu pengembang dan analis data memvalidasi dan melakukan debug ekspresi JSONPath dengan mengujinya langsung terhadap dokumen JSON sampel. Alat ini menghilangkan penebakan saat bekerja dengan API, file konfigurasi, atau struktur data kompleks yang memerlukan navigasi jalur yang tepat.
Untuk menggunakan alat ini, tempel data JSON Anda ke kolom input dan masukkan ekspresi JSONPath ke kolom ekspresi. Saat Anda mengetik, pengujian langsung menunjukkan elemen mana yang cocok dengan ekspresi Anda, beserta nilainya. Pola umum mencakup $. untuk akses root, .property untuk properti objek, [0] untuk indeks array, dan [*] untuk memilih semua elemen array. Hasil menampilkan semua jalur dan nilai yang cocok, memudahkan untuk menyempurnakan kueri Anda hingga mengekstrak dengan tepat apa yang Anda butuhkan.
Pertanyaan yang Sering Diajukan
Implementasi Kode
# pip install jsonpath-ng
from jsonpath_ng import parse
data = {
"store": {
"book": [
{"title": "Moby Dick", "author": "Herman Melville", "price": 8.99},
{"title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "price": 12.99},
{"title": "1984", "author": "George Orwell", "price": 6.99}
]
}
}
# Match all book titles
expr = parse("$.store.book[*].title")
titles = [match.value for match in expr.find(data)]
print(titles)
# ['Moby Dick', 'The Great Gatsby', '1984']
# Filter books cheaper than $10
expr2 = parse("$.store.book[?(@.price < 10)]")
cheap_books = [match.value for match in expr2.find(data)]
print(cheap_books)
# [{'title': 'Moby Dick', ...}, {'title': '1984', ...}]
# Recursive descent: find all authors anywhere in the document
expr3 = parse("$..author")
authors = [match.value for match in expr3.find(data)]
print(authors)
# ['Herman Melville', 'F. Scott Fitzgerald', 'George Orwell']Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.