tpmjs/packages/tools/official/json-path-query
Ajax Davis 5926373be6 chore: update ai package to 6.0.49 across all packages
- Updated all packages from ai@6.0.23 to ai@6.0.49
- Added pnpm override to ensure consistent version
- Created changeset for publishing affected packages
2026-01-25 11:33:03 +10:00
..
src feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
CHANGELOG.md chore: version packages 2025-12-31 23:54:47 +10:00
package.json chore: update ai package to 6.0.49 across all packages 2026-01-25 11:33:03 +10:00
README.md feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsconfig.json feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsup.config.ts feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00

@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