# jsonwalk

> Recursively traverse JSON data with jq syntax and apply functions on it's fields

Latest version **0.1.2** (published 2020-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonwalk
pnpm add jsonwalk
yarn add jsonwalk
bun add jsonwalk
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2020-10-31 |
| First published | 2020-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Silur |
| Maintainers | silur |
| Keywords | json, deep, recursive, walk, traverse |

## Links

- npm: https://www.npmjs.com/package/jsonwalk
- Repository: https://github.com/Silur/jsonwalk
- Homepage: https://github.com/Silur/jsonwalk#readme
- Issues: https://github.com/Silur/jsonwalk/issues
- npm.io page: https://npm.io/package/jsonwalk

## Dependencies (2)

- [chai](https://npm.io/package/chai.md) ^4.2.0
- [mocha](https://npm.io/package/mocha.md) ^8.1.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.2 (latest) — 2020-10-31
- 0.1.1 — 2020-09-05
- 0.1.0 — 2020-09-05

## README

# jsonwalk [![npm](https://img.shields.io/npm/v/jsonwalk)](https://www.npmjs.com/package/jsonwalk)
This tool allows you to walk a JSON object recursively given a jq-like query array, and run function transforms on the fields contained in this schema.

## Example

```javascript

const jsonwalk = require('jsonwalk')

const myJson = {
    "Product Name": "Bowler Hat",
      "ProductID": 858383,
      "SKU": "0406654608",
      "Description": {
              "Colour": "Purple",
              "Width": 300,
              "Height": 200,
              "Depth": 210,
              "Weight": 0.75
             },
      "Price": 34.45,
      "Quantity": 2,
    "tags": ['clothing', 'hats']

}

const query = ['Description.Width', 'Description.Height']

function makeBigger(key, value) {
    console.log(value)
    return value*2 // double the size
}

(async () => {
  jsonwalk.walk(myJson, query, makeBigger)
})()
/* should return: 
 * 300
 * 200
 */

```

Like in `jq`, you can specify array elements with `$`:

```javascript

const query = ['Description.tags.$']

function makeBigger(key, value) {
	console.log(value)
	return value.toUpperCase()
}
(async () => {
  jsonwalk.walk(myJson, query, makeBigger)
})()
/* should return
 * clothing
 * hats
 */

```

You can reverse the functionality (run the callback on all fields **not** in the query) by adding another boolean param at the end:

`jsonwalk.walk(myJson, query, makeBigger, true) // true is reversed`

---
_Source: https://npm.io/package/jsonwalk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
