https://github.com/json-schema-tools/traverse
Traverse and optionally mutate a json schema and all it's subschema
https://github.com/json-schema-tools/traverse
Last synced: about 1 month ago
JSON representation
Traverse and optionally mutate a json schema and all it's subschema
- Host: GitHub
- URL: https://github.com/json-schema-tools/traverse
- Owner: json-schema-tools
- License: apache-2.0
- Created: 2020-01-28T02:09:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-01-21T10:18:57.000Z (4 months ago)
- Last Synced: 2025-04-11T21:02:34.229Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://json-schema-tools.github.io/traverse/
- Size: 1.52 MB
- Stars: 10
- Watchers: 1
- Forks: 3
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# JSON Schema Traverse
![]()
![]()
![]()
![]()
![]()
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](https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html) as it traverses## Getting Started
```sh
npm install @json-schema-tools/traverse
``````js
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/
## Features Todo
- unevaluatedItems (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.3.1.3)
- unevaluatedProperties (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.3.2.4)
- contains (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.3.1.4)
- propertyNames (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.3.2.5)### Contributing
How to contribute, build and release are outlined in [CONTRIBUTING.md](CONTRIBUTING.md), [BUILDING.md](BUILDING.md) and [RELEASING.md](RELEASING.md) respectively. Commits in this repository follow the [CONVENTIONAL_COMMITS.md](CONVENTIONAL_COMMITS.md) specification.