# @stoplight/json-schema-tree

Latest version **4.0.0** (published 2024-01-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @stoplight/json-schema-tree
pnpm add @stoplight/json-schema-tree
yarn add @stoplight/json-schema-tree
bun add @stoplight/json-schema-tree
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2024-01-23 |
| First published | 2020-12-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10.18 |
| Dependencies | 5 |
| Unpacked size | 227.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Stoplight |
| Maintainers | stoplight-devops |

## Links

- npm: https://www.npmjs.com/package/@stoplight/json-schema-tree
- Repository: https://github.com/stoplightio/json-schema-tree
- Homepage: https://github.com/stoplightio/json-schema-tree#readme
- Issues: https://github.com/stoplightio/json-schema-tree/issues
- npm.io page: https://npm.io/package/@stoplight/json-schema-tree

## Dependencies (5)

- [magic-error](https://npm.io/package/magic-error.md) 0.0.1
- [@stoplight/json](https://npm.io/package/@stoplight/json.md) ^3.12.0
- [@types/json-schema](https://npm.io/package/@types/json-schema.md) ^7.0.7
- [@stoplight/lifecycle](https://npm.io/package/@stoplight/lifecycle.md) ^2.3.2
- [@stoplight/json-schema-merge-allof](https://npm.io/package/@stoplight/json-schema-merge-allof.md) ^0.8.0

## Recent versions

- 4.0.0 (latest) — 2024-01-23
- 1.1.0-beta.1 (beta) — 2021-06-21
- 3.0.0 — 2023-12-14
- 2.3.1 — 2023-11-17
- 2.3.0 — 2023-11-15
- 2.2.5 — 2023-08-09
- 2.2.4 — 2023-08-02
- 2.2.3 — 2023-05-15
- 2.2.2 — 2022-08-02
- 2.2.1 — 2022-05-17
- 2.2.0 — 2022-01-20
- 2.1.3 — 2021-12-01
- 2.1.2 — 2021-11-05
- 2.1.1 — 2021-06-30
- 2.1.0 — 2021-06-21
- … 14 more at https://npm.io/package/@stoplight/json-schema-tree/versions

## README

# @stoplight/json-schema-tree

<!-- BADGES -->

### Use cases

- json-schema-viewer
- json-schema-editor
- masking

### Installation

Supported in modern browsers and Node.JS (>=10.18).

```bash
# latest stable
yarn add @stoplight/json-schema-tree
```

### Usage

```js
import { SchemaTree, SchemaNodeKind, isRegularNode } from '@stoplight/json-schema-tree';

const tree = new SchemaTree(mySchema);
const ALLOWED_DEPTH = 2;

tree.walker.hookInto('stepIn', node => tree.walker.depth <= ALLOWED_DEPTH); // if flattening is needed, this might need to be tweaked to account for the scenarios where certain nodes can be merged (i.e. arrays)

tree.walker.hookInto('filter', node => {
  return !isRegularNode(node) || node.types === null || !node.types.includes(SchemaNodeKind.Integer); // if a schema property is of type integer, it won't be included in the tree
});

tree.populate();

tree.root; // populated tree
```

### Contributing

1. Clone repo.
2. Create / checkout `feature/{name}`, `chore/{name}`, or `fix/{name}` branch.
3. Install deps: `yarn`.
4. Make your changes.
5. Run tests: `yarn test.prod`.
6. Stage relevant files to git.
7. Commit: `yarn commit`. _NOTE: Commits that don't follow the
   [conventional](https://github.com/marionebl/commitlint/tree/master/%40commitlint/config-conventional) format will be
   rejected. `yarn commit` creates this format for you, or you can put it together manually and then do a regular
   `git commit`._
8. Push: `git push`.
9. Open PR targeting the `master` branch.

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