DevToolBox

JSONPath Query Tester

JSONデータに対してJSONPath式でクエリをテスト・実行します。

How to Use the JSONPath Query Tester

This free online JSONPath tester lets you evaluate JSONPath expressions against your JSON data instantly. Paste your JSON into the input area, enter a JSONPath expression, and click "Execute" to see the matched results. All processing happens entirely in your browser with no data sent to any server.

Supported JSONPath Syntax

  • $ - Root object reference
  • .property - Child property access (dot notation)
  • [index] - Array index access (zero-based)
  • [*] - Wildcard matching all array elements or object values
  • ..property - Recursive descent to find property at any depth

Common Use Cases

JSONPath is commonly used to extract specific data from complex JSON structures returned by APIs. For example, you might use $.data[*].name to extract all names from an array, or $..id to find every id field regardless of nesting depth. This tool is invaluable for testing queries before using them in code with libraries like Jayway JSONPath, json-path, or jq.

Tips for Writing JSONPath Expressions

Always start your expression with $ to reference the root. Use dot notation for simple property access and bracket notation for array indices. The recursive descent operator .. is powerful but can return many results from deeply nested structures. Test your expressions with sample data before applying them to production queries.

JSONPath Query Testerの使い方

このツールはJSONデータに対してJSONPath式を使ったクエリをブラウザ上でテスト・実行できます。JSONデータを入力し、JSONPath式を指定して「実行」をクリックすると、マッチした結果が配列で表示されます。APIレスポンスからのデータ抽出やフィルタリングのテストに最適です。すべての処理はクライアントサイドで完結します。

対応している演算子は $(ルート)、.property(ドット記法)、[0](配列インデックス。[-1] の負数指定も可)、[*](ワイルドカード)、..property(再帰降下)です。フィルタ式 [?(...)] やスライス [0:2] は未対応のため、それらが必要な場合は後述のライブラリ(jsonpath / jsonpath-ng / jq)で実行してください。

活用例1: APIレスポンスから必要なフィールドだけを抽出する

深くネストしたAPIレスポンスから特定の値を取り出すコードを書く前に、まず式が正しいかをここで検証します。実際のレスポンスを貼り付け、$.data[*].id のような式を試行錯誤して確定させてから、アプリケーションコードに転記すると手戻りがありません。レスポンス全体ではなく問題の箇所だけを抜粋して貼れば、機密フィールドを含めずにテストできます。

活用例2: kubectl などCLIツールのJSONPath指定を事前検証する

kubectl get pods -o jsonpath=... は中括弧で囲む独自方言(例: {.items[*].metadata.name})ですが、パス構造そのものの確認には本ツールが役立ちます。kubectl get pods -o json の出力を貼り付けて目的の値に到達するパスを探り、確定してから kubectl の書式に書き換える、という流れが実務では最も速い方法です。

活用例3: 巨大なJSONの構造調査

ログやデータエクスポートの巨大なJSONで「目的のキーがどの階層にあるか分からない」とき、$..キー名 の再帰降下で全階層を一括検索できます。マッチ件数と中身を確認したら、誤マッチを避けるために $.store.books[*].price のような明示的なパスへ書き換えて使うのが安全です。

よくあるエラーと対処 / Common Errors and Fixes

JSONPathは構文エラーで落ちるより「黙って空の [] が返る」ことが多く、原因の切り分けが難しい言語です。頻出パターンをまとめました。

JSONPath rarely throws — it silently returns an empty [] instead, which makes debugging tricky. Here are the most common failure patterns.

症状 / Symptom原因 / Cause対処 / Fix
結果が常に空の []
Result is always an empty []
式が $ で始まっていない(store.books など)
Expression does not start with $
必ず $ をルートとして書く($.store.books
Always start from the root: $.store.books
$.store.book が何も返さない
$.store.book returns nothing
キー名のタイプミス。大文字小文字も区別される
Key typo; matching is case-sensitive
JSONを整形してキー名を正確に確認(booksBooks は別物)
Pretty-print the JSON and copy the exact key name
$['store'] が効かない
$['store'] does not match
本ツールのブラケット記法は数値インデックスと * のみ対応
This tester's brackets accept numeric indices and * only
ドット記法 $.store を使う。クォート付きブラケットはライブラリ側で
Use dot notation here; quoted brackets work in full libraries
スライス [0:2] が無視される
Slice [0:2] is ignored
配列スライスは本ツール未対応(RFC 9535 標準では有効)
Slices are not supported here, though valid in RFC 9535
[0][1] と個別指定するか、jsonpath-ng / Jayway 等で実行
Use individual indices, or run in jsonpath-ng / Jayway
フィルタ式 [?(@.price < 10)] が効かない
Filter [?(@.price < 10)] does not work
フィルタ式 ?() は本ツール未対応
Filter expressions are not evaluated by this tester
構造確認に本ツールを使い、フィルタは jq の select() やライブラリで
Verify the path here; apply filters with jq select() or a library
$..price の結果が想定より多い
$..price returns more than expected
再帰降下 .. は全階層の同名キーをすべて拾う
Recursive descent matches the key at every depth
範囲を限定するなら $.store.books[*].price のように明示パスを使う
Switch to an explicit path to narrow the scope
[-1] が他の環境で動かない
[-1] fails in another environment
負のインデックス対応は実装によって異なる
Negative-index support varies by implementation
本ツールは [-1] 対応。移植先ライブラリの仕様を必ず確認
Supported here; always check the target library's spec
ドットを含むキー(app.version 等)が辿れない
Keys containing dots cannot be reached
ドット記法ではキー名が appversion に分割される
Dot notation splits the key at the dot
標準実装では $['app.version'] と書く。本ツールではライブラリでの実行を検討
Use quoted brackets in a standard implementation

言語別コード例 / Code Examples by Language

ここで検証したJSONPath式をコードに組み込む際の最小サンプルです。フィルタ式やスライスもライブラリ側では使えます。

Minimal snippets for running the expressions you tested here in real code. Filters and slices are available in these libraries.

JavaScript (jsonpath)

// npm install jsonpath
const jp = require("jsonpath");

const data = JSON.parse(input);
const authors = jp.query(data, "$.store.books[*].author");
// ["Nigel Rees", "Evelyn Waugh", ...]

// フィルタ式も使える / Filter expressions are supported
const cheap = jp.query(data, "$.store.books[?(@.price < 10)]");

Python (jsonpath-ng)

# pip install jsonpath-ng
from jsonpath_ng import parse
from jsonpath_ng.ext import parse as parse_ext  # フィルタ式用 / for filters

authors = [m.value for m in parse("$.store.books[*].author").find(data)]

# フィルタ式は ext パーサが必要 / Filters require the ext parser
cheap = [m.value
         for m in parse_ext("$.store.books[?(@.price < 10)]").find(data)]

Go (ohler55/ojg)

import (
    "github.com/ohler55/ojg/jp"
    "github.com/ohler55/ojg/oj"
)

data, _ := oj.ParseString(jsonStr)
x, _ := jp.ParseString("$.store.books[*].author")
authors := x.Get(data) // []any

Shell (jq 相当 / jq equivalents)

# JSONPath: $.store.books[*].author
jq '.store.books[].author' data.json

# JSONPath: $..price (再帰降下 / recursive descent)
jq '.. | .price? // empty' data.json

# JSONPath: $.store.books[?(@.price < 10)] のフィルタ相当
jq '.store.books[] | select(.price < 10)' data.json

Before / After 実例 / Before & After

サンプルJSON(書店データ)に対する代表的なクエリと結果です。

例1: 配列の全要素から特定フィールドを抽出 / Extract a field from every element

式 / Expression: $.store.books[*].author

["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J.R.R. Tolkien"]

例2: 再帰降下で全階層の price を収集 / Collect every price recursively

式 / Expression: $..price

[8.95, 12.99, 8.99, 22.99, 19.95]

books 配下の4件に加え、bicycle.price(19.95)も拾われる点に注意。

Note that bicycle.price (19.95) is also matched, not just the four books.

例3: 負のインデックスで末尾要素を取得 / Get the last element with a negative index

式 / Expression: $.store.books[-1].title

["The Lord of the Rings"]

Why browser-only? / なぜブラウザ完結か

JSONPath expressions are almost always tested against real API responses — and real responses carry access tokens, session identifiers, e-mail addresses, internal record IDs, and other data you should never paste into a server-hosted tool. Even if such a service claims to discard your input, the payload still travels over the network and may be logged by proxies or the service itself. This tester evaluates every expression locally: the JSON is parsed with JSON.parseand the path is walked by plain JavaScript running in your tab. No request is made when you click "Execute." You can verify this yourself — open DevTools, switch to the Network tab, run a query, and watch the tab stay empty. That makes it safe to debug queries against production payloads, staging dumps, or customer data exports without involving a third party.

JSONPathのテスト対象はたいてい本物のAPIレスポンスであり、アクセストークンや内部ID、メールアドレスが含まれます。本ツールはJSONの解析もパスの評価もすべてブラウザ内のJavaScriptで実行し、「実行」を押しても通信は一切発生しません。DevTools → Network タブが空のままであることで確認できます。

開発をもっと効率的に

PR