Test JSONPath expressions against JSON documents
Common JSONPath Patterns:
$.store.book - Direct path$.store.book[*] - All books$..author - All authors (recursive)$.store.book[0] - First book$.store.book[-1] - Last book$.store.book[?(@.price < 10)] - Filter by priceJSONPath tester evaluates JSONPath expressions against JSON documents to query and extract specific data. Like XPath for XML, JSONPath provides a query language for navigating JSON structures, extracting arrays, filtering objects, and accessing nested values.
Parse JSON input, then parse and evaluate JSONPath expression. Traverse JSON tree following path components: root ($), child (.), recursive descent (..), array index ([n]), wildcards (*), filters ([?()]). Return all matching values.
JSONPath syntax: $ = root, .property = child, ..property = recursive, [n] = array index, [*] = all items, [start:end] = slice, [?(@.price<10)] = filter. Implementations vary (Goessner, Jayway). Some support functions like length(), min(), max().
Extract specific values from JSON responses.
$.data.users[*].nameQuery nested structures for ETL.
$.orders[?(@.status=="pending")]Access specific config values.
$.database.connection.hostExtract fields from JSON logs.
$.events[*].timestamp// Using jsonpath-plus library
import { JSONPath } from 'jsonpath-plus';
const data = {
store: {
books: [
{ title: 'Book A', price: 10, category: 'fiction' },
{ title: 'Book B', price: 15, category: 'tech' },
{ title: 'Book C', price: 8, category: 'fiction' }
],
location: { city: 'Sydney' }
}
};
// Basic queries
JSONPath({ path: '$.store.books[0].title', json: data });
// ['Book A']
JSONPath({ path: '$.store.books[*].title', json: data });
// ['Book A', 'Book B', 'Book C']
// Filter: books under $12
JSONPath({ path: '$.store.books[?(@.price<12)]', json: data });
// [{ title: 'Book A', ... }, { title: 'Book C', ... }]
// Recursive: all prices
JSONPath({ path: '$..price', json: data });
// [10, 15, 8]
// Slice: first two books
JSONPath({ path: '$.store.books[0:2]', json: data });
// [{ title: 'Book A', ... }, { title: 'Book B', ... }]Common JSONPath patterns. jsonpath-plus is a popular JS library implementing extended JSONPath.
Use JSONPath tester when querying JSON APIs, extracting specific data from complex JSON structures, testing JSONPath expressions, or learning JSONPath syntax.
JSONPath is a query language spec, jq is a full processing tool. JSONPath extracts data, jq transforms it. Both navigate JSON but jq has more power (conditionals, functions, output formatting).