Home/Tools/@tpmjs/tools-json-path-query

jsonPathQueryTool

@tpmjs/tools-json-path-query

Query JSON data using JSONPath expressions. Supports filtering, recursive descent, and complex queries like "$.users[?(@.age > 18)].name" or "$..book[?(@.price < 10)]".

Official
data
v0.1.0
MIT

Interactive Playground

Test @tpmjs/tools-json-path-query (jsonPathQueryTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-json-path-query
pnpm add @tpmjs/tools-json-path-query
yarn add @tpmjs/tools-json-path-query
bun add @tpmjs/tools-json-path-query
deno add npm:@tpmjs/tools-json-path-query

2. Import the tool

import { jsonPathQueryTool } from '@tpmjs/tools-json-path-query';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { jsonPathQueryTool } from '@tpmjs/tools-json-path-query';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { jsonPathQueryTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
json
Required
Type: objectarray

JSON data to query (object or array)

path
Required
Type: string

JSONPath expression (e.g., "$.users[*].name", "$..price", "$.items[?(@.active)]")

Schema extracted: 1/1/2026, 8:18:12 AM

README

@tpmjs/tools-json-path-query

Query JSON using JSONPath expressions.

Installation

npm install @tpmjs/tools-json-path-query

Usage

import { jsonPathQueryTool } from '@tpmjs/tools-json-path-query';

const data = {
  users: [
    { name: 'Alice', age: 25, active: true },
    { name: 'Bob', age: 17, active: false },
    { name: 'Carol', age: 30, active: true }
  ]
};

// Find all active users
const result = await jsonPathQueryTool.execute({
  json: data,
  path: '$.users[?(@.active)].name'
});

console.log(result.results);
// => ["Alice", "Carol"]

console.log(result.count);
// => 2

console.log(result.paths);
// => ["$['users'][0]['name']", "$['users'][2]['name']"]

JSONPath Examples

// Get all user names
path: '$.users[*].name'

// Find users older than 18
path: '$.users[?(@.age > 18)]'

// Recursive descent - find all 'price' fields
path: '$..price'

// Array slicing - first 3 items
path: '$.items[0:3]'

// Multiple conditions
path: '$.users[?(@.age > 18 && @.active)]'

Features

  • Powerful queries: Full JSONPath syntax support
  • Filtering: Filter arrays with expressions like ?(@.age > 18)
  • Recursive descent: Find nested values with ..
  • Path tracking: Returns the JSONPath to each result
  • Array operations: Slicing, filtering, and wildcard selection

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
json
jsonpath
query
data

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai