Package detail

@json-schema-tools/traverse

json-schema-tools128.5kApache-2.01.11.0

This package exports a method that will traverse a JSON-Schema, calling a mutation function for each sub schema found. It is useful for building tools to work with JSON Schemas.

readme

JSON Schema Traverse

CircleCI branch npm GitHub release GitHub commits since latest release

This package exports a method that will traverse a JSON-Schema, calling a "mutation" function for each sub schema found. It is useful for building tools to work with JSON Schemas.

Features

  • circular reference detection & handling
  • synchronous - doesn't touch the filesystem or make network requests.
  • easily perform schema mutations while traversing
  • optional mutability (toggle updating original schema object)
  • returns JSONPaths as it traverses

Getting Started

npm install @json-schema-tools/traverse
const traverse = require("@json-schema-tools/traverse").default;
//import traverse from "@json-schema-tools/traverse"

const mySchema = {
  title: "baz",
  type: "object",
  properties: {
    foo: {
      title: "foo",
      type: "array",
      items: { type: "string" }
    },
    bar: {
      title: "bar",
      anyOf: [
        { title: "stringerific", type: "string" },
        { title: "numberoo", type: "number" }
      ]
    }
  }
};

traverse(mySchema, (schemaOrSubschema) => {
  console.log(schemaOrSubschema.title);
});

API Docs

https://json-schema-tools.github.io/traverse/

Contributing

How to contribute, build and release are outlined in CONTRIBUTING.md, BUILDING.md and RELEASING.md respectively. Commits in this repository follow the CONVENTIONAL_COMMITS.md specification.

changelog

1.11.0 (2025-06-20)

Features

  • support additional schema keywords (6c0a7fa)

1.10.4 (2024-05-07)

Bug Fixes

  • update node and bump meta-schema (a9480cd)

1.10.3 (2024-03-12)

Bug Fixes

  • add self-review suggestions (f1f95e5)
  • all tests passing (0c180b0)
  • bug fixed and tests fixed (6f9b06e)
  • parent fixups and testing (77a77f6)
  • simplify code a bit where possible (b3eae12)
  • undo debugging stuff (516cea9)

1.10.2 (2024-03-11)

Bug Fixes

1.10.1 (2022-10-06)

Bug Fixes

  • additionalItems should always be traversed (c259f3c)
  • circle ci config fixed (cf5b7f9)
  • clean up circle config a little bit (83bf89a)

1.10.0 (2022-10-05)

Bug Fixes

  • add tests around MutationFunction.parent (33a06a0)

Features

  • mutation function is called with parent schema (2e26427)

1.9.0 (2022-10-04)

Bug Fixes

  • add docs link to readme (3252c23)
  • dont use jsdom for jest (140e7fa)
  • node version in circle was wrong (b80ed78)
  • remove outdated typedoc setting (0959a1e)
  • update node and deps (d318d06)

Features

  • use json-path for path param (970d03a)

1.8.1 (2021-06-24)

Bug Fixes

  • update to latest json schema meta schema (a00b1ee)

1.8.0 (2021-06-18)

Bug Fixes

Features

  • mutation functions isCycle param working properly now (4a6ad09)

1.7.8 (2021-06-08)

Bug Fixes

  • big dep bump for next release (12bb092)
  • get typedoc working again (43fa0e8)
  • github workflow for linting fixup (191c69e)
  • remove dependabot status from readme (ecfffc9)

1.7.7 (2020-11-03)

Bug Fixes

1.7.6 (2020-10-29)

Bug Fixes

1.7.5 (2020-10-23)

Bug Fixes

  • incorrect open collective username (6bb07ef)

1.7.4 (2020-10-23)

Bug Fixes

1.7.3 (2020-10-23)

Bug Fixes

  • add lint script to package.json (18bdfff)
  • update node version (d4c9809)

1.7.2 (2020-10-23)

Bug Fixes

1.7.1 (2020-10-23)

Bug Fixes

  • eslint issues resolved by updating linter (eabb64a)
  • test was highlighting an issue with jest that was fixed (e1c5d69)
  • update deps (99a7ba2)

1.7.0 (2020-09-21)

Bug Fixes

  • add space (9a7e27e)
  • added array pathing (936105a)
  • added array pathing (9b6d723)
  • change from JSON-Path spec to RFC 6901 for path output (768bfca)
  • change from JSON-Path spec to RFC 6901 for path output (ccd369a)
  • clean up stringify code (a639c35)
  • clean up stringify code (bd28424)
  • remove implicit typecasting (e534193)
  • remove merge artifact (858ef35)
  • remove push/pop to improve performance (9bf5eff)
  • standardize pathstack to string array (b36ef4a)
  • standardize pathstack to string array (48550f7)
  • update index.test.ts to use path (7d9cedf)
  • update index.test.ts to use path (5bc96db)
  • update mutation function args and delete obsolete test file (3fb1bfd)
  • update mutation function args and delete obsolete test file (4607ae1)

Features

  • add path to mutator function (85551ab)
  • add path to mutator function (e9137d3)

1.6.0 (2020-08-24)

Bug Fixes

  • add implementation (c0689d2)
  • add more tests (d14e6d7)
  • bfs with skipfirst working as well as option defaulting (fdbbfe9)
  • found a test case that highlights an issue (a4a86be)

Features

1.5.0 (2020-07-28)

Features

1.4.2 (2020-07-21)

Bug Fixes

1.4.1 (2020-07-21)

Bug Fixes

1.4.0 (2020-07-21)

Bug Fixes

Features

  • update to new meta-schema (82a133e)

1.3.1 (2020-07-20)

Bug Fixes

1.3.0 (2020-07-15)

Bug Fixes

Features

  • add cycle tracking to the mutation function interface (fe8ea52)

1.2.4 (2020-07-07)

Bug Fixes

1.2.3 (2020-07-07)

Bug Fixes

  • items cycle with first mutation skip (c54d0d5)

1.2.2 (2020-07-01)

Bug Fixes

  • change sem rel ordering (2370165)

1.2.1 (2020-07-01)

Bug Fixes

1.2.0 (2020-06-29)

Bug Fixes

  • use circleci context and parallelize more (13111d5)

Features

  • add an option that toggles mutating original schema (#55) (01506d8)

1.1.2 (2020-06-27)

Bug Fixes

  • update to latest JSON schema meta schema (#53) (c02585d)

1.1.1 (2020-06-25)

Bug Fixes

  • add more tests around mutation and merging (d676794)
  • micro refactor (087e905)

1.1.0 (2020-06-25)

Features

1.0.1 (2020-06-19)

Bug Fixes

1.0.0 (2020-01-28)

Features