# json-schema-preset

> Produce a suitable default template / preset based on a JSON-Schema.

Latest version **1.0.1** (published 2023-10-09) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-10-09 |
| First published | 2021-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 6 |
| Unpacked size | 18.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mdornseif |
| Keywords | JSON, schema, JSON-Schema, Data Generation |

## Links

- npm: https://www.npmjs.com/package/json-schema-preset
- Repository: https://github.com/mdornseif/json-schema-preset
- Homepage: https://github.com/mdornseif/json-schema-preset#readme
- Issues: https://github.com/mdornseif/json-schema-preset/issues
- npm.io page: https://npm.io/package/json-schema-preset

## Dependencies (6)

- [json-schema](https://npm.io/package/json-schema.md) ^0.4.0
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.2
- [json-schema-default](https://npm.io/package/json-schema-default.md) ^1.0.0
- [json-schema-traverse](https://npm.io/package/json-schema-traverse.md) ^1.0.0
- [json-schema-empty-arrays](https://npm.io/package/json-schema-empty-arrays.md) ^1.0.0
- [json-schema-empty-strings](https://npm.io/package/json-schema-empty-strings.md) ^1.0.2

## 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

- 1.0.1 (latest) — 2023-10-09
- 1.0.0 — 2021-12-20

## README

[![npm version](https://badge.fury.io/js/json-schema-preset.svg)](https://badge.fury.io/js/json-schema-preset)

# json-schema-preset

Produce a suitable default template / preset based on a [JSON-Schema](https://json-schema.org), e.g. for pre-filling a form.

It is in the spirit of [json-schema-empty](https://www.npmjs.com/package/json-schema-empty).
json-schema-empty is different in that it closely observes the `required` properties and only adds required values.

json-schema-preset on the other hand copies default values not caring if they are required or not. It also ensures that no string properties are `null` but preset with an empty string (`""`). Arrays without defaults are replaced by `[]`.

You can generate a preset for a form etc. like this:

```js
import { jsonPreset } from 'json-schema-preset';

const preset = jsonPreset(schema);
```

If you want to ensure that an existing object has all missing properties filled in by `jsonPreset()` give it as a second parameter:

```js
import { jsonPreset } from 'json-schema-preset';

const dataWithPreset = jsonPreset(schema, { data: 'foobar' });
```

# See also

- [json-schema-empty](https://github.com/romeovs/json-schema-empty)
- [json-schema-default](https://www.npmjs.com/package/json-schema-default)
- [json-schema-empty-strings](https://www.npmjs.com/package/json-schema-empty-strings/)
- [json-schema-empty-arrays](https://www.npmjs.com/package/json-schema-empty-arrays/)
- [AJV](https://ajv.js.org/guide/modifying-data.html#assigning-defaults)

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