jsonpath-plus nested store query: working versions (tested 2026-10-16)
Query a nested store JSON with jsonpath-plus using filters, recursive descent and wildcards, asserting matched values and paths with resultType value and path. Offline.
passed7 passed · 0 failed2026-10-16 20:33 UTC- Status
- passed
- Last passed
- 2026-10-16 20:33 UTC
- Tests
- 7 / 7
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
jsonpath-plus@11.2.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38962988948
The code
Exactly the files that passed. Your agent can pull them with get_recipe("jsonpath-plus-query") (install), or see them on GitHub.
package.json
{
"name": "jsonpath-plus-query",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"jsonpath-plus": "11.2.1"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/query.ts
import { JSONPath } from "jsonpath-plus";
export type Author = { name: string };
export type StoreBook = {
title: string;
price: number;
category: string;
author: Author;
};
export type Store = {
store: {
name: string;
book: StoreBook[];
bicycle: { color: string; price: number };
};
};
export const store: Store = {
store: {
name: "Corner Shop",
book: [
{ title: "Book A", price: 10, category: "fiction", author: { name: "Ann" } },
{ title: "Book B", price: 20, category: "reference", author: { name: "Bob" } },
{ title: "Book C", price: 30, category: "fiction", author: { name: "Cara" } },
],
bicycle: { color: "red", price: 100 },
},
};
export function values<T = unknown>(json: unknown, path: string): T[] {
const result = JSONPath({ path, json, resultType: "value" });
return result as unknown as T[];
}
export function paths(json: unknown, path: string): string[] {
const result = JSONPath({ path, json, resultType: "path" });
return result as unknown as string[];
}
test/query.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { store, values, paths, type StoreBook } from "../src/query.ts";
function simplify(path: string): string {
return path
.replace(/\[['"]([^'"]+)['"]\]/g, ".$1")
.replace(/\[(\d+)\]/g, ".$1");
}
test("filter selects books under a price", () => {
const titles = values<string>(store, "$.store.book[?(@.price < 20)].title");
assert.deepEqual(titles, ["Book A"]);
});
test("recursive descent collects every price", () => {
const prices = values<number>(store, "$..price");
assert.deepEqual(prices, [10, 20, 30, 100]);
});
test("wildcard maps over the book array", () => {
const names = values<string>(store, "$.store.book[*].author.name");
assert.deepEqual(names, ["Ann", "Bob", "Cara"]);
});
test("resultType value returns matched nodes", () => {
const books = values<StoreBook>(store, "$.store.book[?(@.category == 'fiction')]");
assert.deepEqual(books.map((b) => b.title), ["Book A", "Book C"]);
});
test("resultType path returns matched locations", () => {
const found = paths(store, "$.store.book[*].title");
assert.deepEqual(found.map(simplify), [
"$.store.book.0.title",
"$.store.book.1.title",
"$.store.book.2.title",
]);
});
test("returned paths round-trip back to the same values", () => {
const found = paths(store, "$.store.book[*].title");
const roundTripped = found.map((p) => values<string>(store, p)[0]);
assert.deepEqual(roundTripped, ["Book A", "Book B", "Book C"]);
});
test("wildcard over an object collects its values", () => {
const details = values<unknown>(store, "$.store.bicycle.*");
assert.deepEqual(details, ["red", 100]);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.