Test JSONPath queries on JSON data. Extract values with $.store.book[*].author syntax. Filter arrays, select nested fields. JSONPath vs jq comparison.
Use this free online JSONPath Query directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.
What is JSONPath Evaluator & Query Builder?
JSONPath evaluator tests JSONPath expressions (queries) against JSON data to extract specific values, similar to XPath for XML. Query syntax: $.store.book[*].author (all book authors), $.store.book[?(@.price < 10)] (books under $10), $..author (all authors in document, deep scan). Tool validates JSONPath syntax, shows matched results (array of values), highlights matched paths. Supports: dot notation ($.store.book), bracket notation ($['store']['book']), array slicing ($.book[0:2]), filters (@.price < 10), wildcards (*), recursive descent (..). Useful for: API response parsing (extract specific fields), data transformation (map JSON to new structure), testing queries before code implementation (validate JSONPath), learning JSONPath syntax (interactive examples).
Recursive descent: Deep scan: $..author (all 'author' fields at any depth). Searches nested objects/arrays. Example: {store: {book: [{author: 'A'}], music: {album: {author: 'B'}}}} → $..author = ['A', 'B'].
Result visualization: Shows matched values (array of results), matched paths ($.store.book[0].author), original JSON with highlighted matches. Debug why query doesn't match expected data.
Why use json path?
Extracting data from complex JSON manually is error-prone (nested objects, arrays). JSONPath provides declarative query syntax.
Test queries interactively: Validate JSONPath before using in code (JavaScript, Python, etc.). See results immediately. Avoid runtime errors (invalid JSONPath syntax).
Extract nested data: Complex JSON (deeply nested objects/arrays) is hard to navigate manually. JSONPath: $.data.users[*].profile.email extracts all emails. Simpler than manual loops.
Filter large datasets: API returns 100s of items, need subset (price < 10, category == 'fiction'). JSONPath filters: $.items[?(@.price < 10)] returns only matching items. No custom code.
Learn JSONPath syntax: Interactive examples: try $.store.book[0], see result. Modify query, see how results change. Faster learning than reading docs.
Debug API responses: API returns unexpected data. Use JSONPath to explore structure: $..author (find all authors), $.*.price (all prices). Understand data shape.
Compare JSONPath vs alternatives: JSONPath vs jq (command-line JSON processor), JSON.parse + JavaScript, XPath (XML). Learn when to use each. JSONPath = simple queries, jq = complex transformations.
When to use json path
Use whenever you need to query or extract data from JSON.
Testing API responses (extract specific fields: user email, product price).
Data transformation (map JSON to CSV, database, new JSON structure).
Filtering large datasets (find items where price < 10, category == 'fiction').
Learning JSONPath syntax (interactive examples, see results immediately).
Debugging JSON parsing (why doesn't query match expected data?).
Config file parsing (extract settings from complex JSON config files).
Log analysis (query JSON logs: find errors, warnings, specific events).
Comparing JSONPath vs jq (which tool is better for your use case?).
How to use json path
Paste JSON data, write JSONPath query, see results.
Paste JSON data: Input JSON in left pane: {"store": {"book": [{"title": "Book A", "price": 8.99}, {"title": "Book B", "price": 12.99}]}}. Or load from file, API response.
Write JSONPath query: Example queries: $.store.book[*].title (all titles), $.store.book[?(@.price < 10)] (books under $10), $..price (all prices, deep scan). Use autocomplete for syntax help.
Validate syntax: Tool checks JSONPath syntax (valid operators, brackets, quotes). Shows error if invalid: 'Unexpected token at position 5'. Red underline in query.
View results: Right pane shows matched values: ['Book A', 'Book B'] for $.store.book[*].title. Empty array [] = no matches. Check query syntax or data structure.
Debug with path highlighting: Click result → highlights matched path in original JSON. See where data comes from. Useful for deep nested structures.
Refine query: Modify query to get desired data. Add filters ([?(@.price < 10)]), change path ($.store.music instead of $.store.book), use wildcard ($.*). Re-run query.
Export results (optional): Copy results to clipboard (JSON array). Use in code, save to file, paste in another tool (Excel, database).
Key features
Interactive query editor: Write JSONPath, see results instantly. Syntax highlighting, autocomplete, error messages. No coding required.
Array operations: Index: [0] (first), [-1] (last). Slice: [0:2] (first 2), [2:] (from index 2), [:2] (up to index 2). Wildcard: [*] (all items). Length: .length.
Path visualization: Shows matched paths ($.store.book[0].title), highlights in original JSON. Understand where results come from (deep nested data).
Error detection: Invalid syntax → error message with position: 'Unexpected token at position 5'. Suggests fix: missing bracket, wrong operator, invalid filter.
Export results: Copy matched values as JSON array. Use in code (JavaScript, Python), save to file, import to database.
Common use cases
Extract all book titles: JSON: {store: {book: [{title: 'A', price: 8}, {title: 'B', price: 12}]}}. Query: $.store.book[*].title. Result: ['A', 'B']. Extracts all title fields from book array.
Filter books by price: Query: $.store.book[?(@.price < 10)]. Result: [{title: 'A', price: 8}]. Returns only books where price < 10. Filter condition in [?()].
Get first and last items: Query: $.book[0] (first book), $.book[-1] (last book). Negative index counts from end. Alternative: $.book[0:1] (first), $.book[-1:] (last).
Deep scan for all prices: Query: $..price. Finds all 'price' fields at any depth (nested objects/arrays). Example: {store: {book: [{price: 8}], music: {album: {price: 15}}}} → [8, 15].
Array slicing: Query: $.book[0:2] (first 2 items), $.book[2:] (from index 2 to end), $.book[:3] (up to index 3). Python-style slicing (start:end, exclusive end).
Regex filter: Query: $.book[?(@.author =~ /.*Smith/)]. Matches books where author contains 'Smith'. Regex syntax: /.* pattern/. Case-sensitive by default.
Root object/array. All queries start with $. Example: $.store (access 'store' field in root), $.items[0] (first item in 'items' array).
. (dot notation)
Child property. $.store.book (access 'book' in 'store'). Dot notation for simple keys (no spaces, special chars). Alternative: bracket notation $['store']['book'].
.. (recursive descent)
Deep scan. $..author finds all 'author' fields at any depth. Searches nested objects and arrays. Example: {a: {author: 'X'}, b: {c: {author: 'Y'}}} → ['X', 'Y'].
* (wildcard)
All elements. $.store.* (all fields in 'store'), $.items[*] (all array items). Useful for iterating over dynamic keys or all array elements.
[n] (array index)
Access by index. $.items[0] (first item), $.items[2] (third item), $.items[-1] (last item). Negative index counts from end (-1 = last, -2 = second-to-last).
[start:end] (slice)
Array slice (Python-style). $.items[0:2] (first 2: index 0, 1), $.items[2:] (from index 2 to end), $.items[:3] (up to index 3, exclusive). Negative index: $.items[-2:] (last 2).
[?(expression)] (filter)
Filter array by condition. $.items[?(@.price < 10)] (items where price < 10). @ = current item. Operators: ==, !=, <, >, <=, >=, =~. Combine: && (and), || (or).
@ (current item)
In filters, @ refers to current array item. $.items[?(@.price < 10)] → @ = each item in 'items'. Access fields: @.price, @.category, @.author.
$['store']['book'] (same as $.store.book). Required for keys with spaces/special chars: $['product name'], $['items-list']. Quotes: single or double.
Common mistakes to avoid
Using [0] to get first item from $.book[*] result (doesn't work in JSONPath)
Why it happens: $.book[*] returns array of items. Can't chain [0] to get first: $.book[*][0] is invalid. [*] expands to all items, [0] expects single array. JSONPath doesn't support post-processing result.
How to avoid it: Use $.book[0] directly (first item) or $.book[0:1] (first item as array). Or get all items ($.book[*]) and process in code: result[0]. JSONPath query returns result, then code processes.
Forgetting @ in filter expressions ($.book[?(price < 10)] instead of @.price)
Why it happens: Filters need @ (current item). price < 10 without @ is invalid (what is 'price'?). @ refers to current array item. @.price = price field of current item.
How to avoid it: Always use @ in filters: $.book[?(@.price < 10)], $.items[?(@.category == 'fiction')]. @ = current item, @.field = access field.
Using double quotes in query string inside JSON (escaping issues)
Why it happens: JSON requires double quotes for strings. JSONPath query inside JSON needs escaping: {"query": "$.book[?(@.category == \"fiction\")]"}. Nested quotes are error-prone.
How to avoid it: Use single quotes in filters: $.book[?(@.category == 'fiction')] (single quotes inside double-quoted JSON string). Or escape double quotes: \"fiction\". Prefer single quotes for simplicity.
Expecting .. (recursive descent) to return paths, not values
Why it happens: $..author returns values (['John', 'Jane']), not paths (['$.store.book[0].author', '$.store.book[1].author']). JSONPath returns matched values, not paths (unless tool shows both).
How to avoid it: JSONPath result = array of values. For paths, use tool's path visualization feature or different library (some support path mode). Standard JSONPath = values only.
Using >= or <= with strings (unexpected results: 'apple' < 'banana' = true)
Why it happens: Comparison operators work on numbers and strings. String comparison = lexicographic (alphabetical): 'apple' < 'banana' = true, 'B' < 'a' = true (uppercase < lowercase in ASCII). Not intuitive.
How to avoid it: Use == for exact string match. For numeric comparison, ensure values are numbers (not strings). $.items[?(@.price >= 10)] works if price is number. If price is string '10', comparison may fail.
Frequently asked questions
What is the difference between JSONPath and jq?
JSONPath = query language for JSON (like XPath for XML). Simple queries: extract fields, filter arrays. jq = command-line JSON processor (more powerful). Supports transformations, functions, piping. Use JSONPath for simple extraction, jq for complex transformations.
What is the difference between $.book[*] and $.book?
$.book returns the entire 'book' array (single value). $.book[*] returns each item in 'book' array (expands to multiple values). Example: $.book = [{...}, {...}], $.book[*] = {...}, {...} (two separate values).
Can JSONPath modify JSON (update, delete fields)?
No, JSONPath is read-only (query/extract only). Cannot modify, insert, delete. For modifications, use jq (transform), JavaScript (JSON.parse + modify), or other tools. JSONPath = query, not mutation.
Why does $..price return duplicate values?
Recursive descent (..) searches all levels. If 'price' appears multiple times at different depths, all are returned. Example: {item: {price: 10, sale: {price: 8}}} → $..price = [10, 8]. Not a bug, searches entire tree.
What is the difference between $.* and $..[*]?
$.* = all fields in root object ($.field1, $.field2). $..[*] = all array items at any depth (recursive descent + wildcard). $.* = top-level only, $..[*] = nested arrays too.
Can I use JSONPath in JavaScript?
Yes, use libraries: jsonpath (npm install jsonpath), jsonpath-plus. Example: const jp = require('jsonpath'); jp.query(data, '$.book[*].title'). Returns array of matched values.
Does JSONPath support sorting or grouping?
No, JSONPath is query-only (filter, extract). No sorting, grouping, aggregation (sum, count). For those, use jq, JavaScript, or other tools. JSONPath = simple queries, not data processing.