# json-schema-empty-strings

> Generate empty strings for all JSON-Schema string fields.

Latest version **1.0.5** (published 2023-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-schema-empty-strings
pnpm add json-schema-empty-strings
yarn add json-schema-empty-strings
bun add json-schema-empty-strings
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2023-02-08 |
| First published | 2021-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 3 |
| Unpacked size | 21.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Maximillian Dornseif |
| Maintainers | mdornseif |

## Links

- npm: https://www.npmjs.com/package/json-schema-empty-strings
- Homepage: https://mdornseif.github.io/json-schema-empty-strings/
- npm.io page: https://npm.io/package/json-schema-empty-strings

## Dependencies (3)

- [vitest](https://npm.io/package/vitest.md) ^0.28.4
- [json-schema-traverse](https://npm.io/package/json-schema-traverse.md) ^1.0.0
- [@types/json-schema-traverse](https://npm.io/package/@types/json-schema-traverse.md) ^1.0.0

## Recent versions

- 1.0.5 (latest) — 2023-02-08
- 1.0.2 — 2021-12-14
- 1.0.0 — 2021-12-14

## README

![NPM License](https://img.shields.io/npm/l/json-schema-empty-strings)
[![NPM Version](https://img.shields.io/npm/v/json-schema-empty-strings)](https://www.npmjs.com/package/json-schema-empty-strings)
[![NPM Types](https://img.shields.io/npm/types/json-schema-empty-strings)](https://www.npmjs.com/package/json-schema-empty-strings)
[![Last Commit](https://img.shields.io/github/last-commit/mdornseif/json-schema-empty-strings)](https://github.com/mdornseif/json-schema-empty-strings)

# json-schema-empty-strings

Generate empty strings for all [JSON-Schema](https://json-schema.org) string fields.

There are four different ways in Javsscript / Typescript to represent "no text":

- `""`
- `null`
- `undefined`
- absence of the corresponding property

In the context of JSON-Schema absence of the corresponding property is widely used to represent absence of strings. Sometimes you might not want that.

For a given schema `jsonEmptyStrings()` generates an object containing empty strings for all properties of `type: string`.

The output can easily [merged](https://www.npmjs.com/package/lodash.merge) with your existing data to get empty strings instead of missing properties.

```js
import { jsonEmptyStrings } from 'json-schema-empty-strings'
import merge from 'lodash.merge'

const finalData = merge({}, jsonEmptyStrings(schema), inputData)
```

Iy you have `null` or `undefined` values in your data [deep-clean](https://www.npmjs.com/package/clean-deep) them before merging:

```js
import { jsonEmptyStrings } from 'json-schema-empty-strings'
import merge from 'lodash.merge'
import cleanDeep from 'clean-deep'

const finalData = merge({}, jsonEmptyStrings(schema), cleanDeep(inputData, {
    emptyArrays: false,
    emptyObjects: false,
    emptyStrings: false,
  })
```

# See also:

- [json-schema-default](https://www.npmjs.com/package/json-schema-default)
- [json-schema-empty](https://www.npmjs.com/package/json-schema-empty)

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