# json-schema-walker

> A system that visits all schema objects in a JSON Schema document and makes callbacks before visiting all of the current schema object's subschemas.

Latest version **4.0.0** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-schema-walker
pnpm add json-schema-walker
yarn add json-schema-walker
bun add json-schema-walker
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-09-07 |
| First published | 2022-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20 |
| Dependencies | 2 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | JonLuca DeCaro |
| Maintainers | jonluca |

## Links

- npm: https://www.npmjs.com/package/json-schema-walker
- Repository: https://github.com/jonluca/json-schema-walker
- Issues: https://github.com/jonluca/json-schema-walker/issues
- npm.io page: https://npm.io/package/json-schema-walker

## Dependencies (2)

- [@types/json-schema](https://npm.io/package/@types/json-schema.md) ^7.0.15
- [@apidevtools/json-schema-ref-parser](https://npm.io/package/@apidevtools/json-schema-ref-parser.md) ^15.3.6

## Recent versions

- 4.0.0 (latest) — 2026-09-07
- 3.3.2 — 2026-07-19
- 3.3.1 — 2026-06-11
- 3.3.0 — 2026-03-23
- 3.2.0 — 2025-11-11
- 3.1.0 — 2025-08-18
- 3.0.2 — 2025-08-15
- 3.0.1 — 2025-06-03
- 3.0.0 — 2025-05-22
- 2.0.0 — 2023-11-08
- 1.1.0 — 2022-08-19
- 1.0.0 — 2022-08-19
- 0.0.4 — 2022-08-01
- 0.0.3 — 2022-08-01
- 0.0.2 — 2022-08-01
- … 1 more at https://npm.io/package/json-schema-walker/versions

## README

# JSON Schema Walker

Loosely based on [CloudFlare's json schema tools](https://github.com/cloudflare/json-schema-tools/tree/master/workspaces/json-schema-walker)

A system that visits schemas in a JSON Schema document and makes callbacks before visiting each schema's subschemas.

Requires Node.js 20 or later.

## Usage

```typescript
import { Walker } from "json-schema-walker";
const schema = {
  // your json schema
};
const walker = new Walker<T>();
await walker.loadSchema(schema, {
  cloneSchema: true,
  dereference: false,
  dereferenceOptions: {
    dereference: {
      circular: "ignore",
    },
  },
});
const convertSchema = (schema) => {
  // do something with the schema properties
};
await walker.walk(convertSchema, walker.vocabularies.DRAFT_07);
const updatedSchema = walker.rootSchema;
```

The vocabulary argument defaults to `walker.vocabularies.DRAFT_07`. Callbacks run synchronously in both walking APIs.
Each schema object is visited once per walk, including when objects are shared or circular. Boolean schemas (`true` and
`false`) are visited at each schema location, so callbacks that modify objects should first check `typeof schema === "object"`.

## Circular references

Passing the options

```json
{
  "dereferenceOptions": {
    "dereference": {
      "circular": "ignore"
    }
  }
}
```

will dereference all non-circular references in your schema.

## Synchronous API

For cases where you don't need `$ref` resolution, you can use the synchronous methods:

```typescript
import { Walker } from "json-schema-walker";
const schema = {
  // your json schema (without $ref)
};
const walker = new Walker<T>();
walker.loadSchemaSync(schema, {
  cloneSchema: true, // only option available
});
const convertSchema = (schema) => {
  // do something with the schema properties
};
walker.walkSync(convertSchema, walker.vocabularies.DRAFT_07);
const updatedSchema = walker.rootSchema;
```

> ⚠️ **Warning**: The synchronous methods (`loadSchemaSync` and `walkSync`) do not support `$ref` resolution. Use the async methods if your schema contains references.

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