본문으로 건너뛰기
🛠️ToolsShed

JSONPath Tester

JSON 데이터에 대한 JSONPath 표현식을 테스트합니다.

이 도구 소개

JSONPath는 JSON 데이터용 쿼리 언어로, XML의 XPath와 유사합니다. JSONPath 테스터는 개발자와 데이터 분석가가 JSON 문서에 대해 JSONPath 식을 직접 테스트하고 검증·디버깅할 수 있도록 돕습니다. API, 구성 파일, 정확한 경로 탐색이 필요한 복잡한 데이터 구조를 다룰 때 이 도구는 추측의 여지를 없애줍니다.

도구를 사용하려면 입력 필드에 JSON 데이터를 붙여넣고 식 필드에 JSONPath 식을 입력하면 됩니다. 입력하면서 테스터는 즉시 어떤 요소가 식과 일치하는지, 그 값이 무엇인지 보여줍니다. $. 는 루트 접근, .property 는 객체 속성, [0] 은 배열 인덱스, [*] 는 모든 배열 요소 선택 등 일반적인 패턴들이 있습니다. 결과는 일치하는 모든 경로와 값을 표시하므로, 필요한 데이터를 정확히 추출할 때까지 쿼리를 쉽게 개선할 수 있습니다.

자주 묻는 질문

코드 구현

# 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.