Installation
Package Manager
Install jsonpathx using your preferred package manager:
bash
npm install @jsonpathx/jsonpathxbash
yarn add @jsonpathx/jsonpathxbash
pnpm add @jsonpathx/jsonpathxbash
bun add @jsonpathx/jsonpathxRequirements
- Node.js: 18.0.0 or higher
- TypeScript: 5.0 or higher (optional, but recommended)
Import
jsonpathx supports both ESM and CommonJS:
typescript
import { JSONPath } from '@jsonpathx/jsonpathx';
// or
import JSONPath from '@jsonpathx/jsonpathx';typescript
const { JSONPath } = require('@jsonpathx/jsonpathx');
// or
const JSONPath = require('@jsonpathx/jsonpathx').default;TypeScript Configuration
For the best experience with TypeScript, ensure your tsconfig.json includes:
json
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}Browser Usage
jsonpathx works in modern browsers:
html
<!-- Via CDN (ESM) -->
<script type="module">
import { JSONPath } from 'https://esm.sh/@jsonpathx/jsonpathx';
const data = { items: [1, 2, 3] };
const result = await JSONPath.query('$.items[*]', data);
console.log(result);
</script>html
<!-- Via CDN (UMD / global) -->
<script src="https://unpkg.com/@jsonpathx/jsonpathx/dist/jsonpathx.umd.min.js"></script>
<script>
const { JSONPath } = window.JSONPathX;
const data = { items: [1, 2, 3] };
JSONPath.query('$.items[*]', data).then(console.log);
</script>Browser Support
- Chrome 57+
- Firefox 52+
- Safari 11+
- Edge 16+
Bundlers
No special bundler configuration is required for the JS engine.
Initialization
Initialization is a no-op for the JS engine. You can call it for API compatibility if you want:
typescript
import { JSONPath } from '@jsonpathx/jsonpathx';
await JSONPath.init();Verification
Verify your installation:
typescript
import { JSONPath } from '@jsonpathx/jsonpathx';
const data = { greeting: 'Hello, jsonpathx!' };
const result = await JSONPath.query('$.greeting', data);
console.log(result); // ['Hello, jsonpathx!']
console.log('jsonpathx is working!');Troubleshooting
TypeScript Errors
If you see TypeScript errors:
- Ensure TypeScript 5.0+ is installed
- Check your
tsconfig.jsonconfiguration - Run
npm install @types/nodeif using Node.js APIs
Performance Issues
If queries are slow:
- Enable caching for repeated queries
- Use the fluent API for complex transformations
Next Steps
- Quick Start Tutorial - Learn the basics
- JSONPath Syntax - Understand the query language
- API Reference - Explore the full API