Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 22.x, 23.x]
node-version: [20.x, 22.x, 23.x, 24.x]

steps:
- name: 📚 checkout
Expand Down
62 changes: 54 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,70 @@ JMESPath is a query language for JSON. It will take a JSON document
as input and transform it into another JSON document
given a JMESPath expression.

## INSTALLATION

```
## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [ESM (Node.js)](#esm-nodejs)
- [CommonJS (Node.js)](#commonjs-nodejs)
- [Browser (UMD)](#browser-umd)
- [API](#api)
- [`search(data, expression)`](#searchdata-jsonvalue-expression-string-jsonvalue)
- [`compile(expression)`](#compileexpression-string-expressionnodetree)
- [Extensions](#extensions-to-original-spec)
- [More Resources](#more-resources)
- [Experimental Features](#experimental-features)

## Installation

```bash
npm install @jmespath-community/jmespath
```

## USAGE
## Usage

### `search(data: JSONValue, expression: string): JSONValue`
### ESM (Node.js)

```javascript
import { search } from "@jmespath-community/jmespath";

search({ foo: { bar: { baz: [0, 1, 2, 3, 4] } } }, "foo.bar.baz[2]");
const data = { foo: { bar: { baz: [0, 1, 2, 3, 4] } } };
const result = search(data, "foo.bar.baz[2]");

console.log(result);
// Outputs: 2
```

### CommonJS (Node.js)

```javascript
const { search } = require("@jmespath-community/jmespath");

const data = { foo: { bar: { baz: [0, 1, 2, 3, 4] } } };
const result = search(data, "foo.bar.baz[2]");

console.log(result);
// Outputs: 2
```

### Browser (UMD)

// OUTPUTS: 2
You can include the UMD build directly in your HTML file. The library will be available under the `jmespath` global variable.

```html
<script src="https://unpkg.com/@jmespath-community/jmespath/dist/index.umd.min.js"></script>
<script>
const data = { foo: { bar: { baz: [0, 1, 2, 3, 4] } } };
const result = jmespath.search(data, "foo.bar.baz[2]");
console.log(result);
// Outputs: 2
</script>
```

## API

### `search(data: JSONValue, expression: string): JSONValue`

In the example we gave the `search` function input data of
`{foo: {bar: {baz: [0, 1, 2, 3, 4]}}}` as well as the JMESPath
expression `foo.bar.baz[2]`, and the `search` function evaluated
Expand Down Expand Up @@ -83,7 +129,7 @@ import { compile, TreeInterpreter } from "@jmespath-community/jmespath";

const ast = compile("foo.bar");

TreeInterpreter.search(ast, { foo: { bar: "BAZ" } });
const result = TreeInterpreter.search(ast, { foo: { bar: "BAZ" } });
// RETURNS: "BAZ"
```

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.0.6/schema.json",
"$schema": "https://biomejs.dev/schemas/2.3.2/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"files": { "ignoreUnknown": false, "includes": ["**", "!**/dist", "!**/coverage", "!**/test/compliance"] },
"formatter": {
Expand Down
Loading