# mt-json-validator

> A simple and extensible json schema validator

Latest version **3.1.6** (published 2018-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install mt-json-validator
pnpm add mt-json-validator
yarn add mt-json-validator
bun add mt-json-validator
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.6 |
| Published | 2018-08-13 |
| First published | 2018-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 40 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Esteban Castro Borsani |
| Maintainers | lebang |
| Keywords | jsonschema, json, validator |

## Links

- npm: https://www.npmjs.com/package/mt-json-validator
- Repository: https://github.com/lebang/tiny-json-validator
- Issues: https://github.com/lebang/tiny-json-validator/issues
- npm.io page: https://npm.io/package/mt-json-validator

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

- 3.1.6 (latest) — 2018-08-13
- 3.1.5 — 2018-08-13
- 3.1.4 — 2018-08-13
- 3.1.3 — 2018-08-13
- 3.1.2 — 2018-08-13
- 3.1.1 — 2018-08-13
- 3.1.0 — 2018-08-13
- 3.0.2 — 2018-08-07
- 3.0.1 — 2018-07-24
- 3.0.0 — 2018-07-24
- 2.0.1 — 2018-07-23
- 2.0.0 — 2018-07-03

## README

# Tiny JSON validator

A Node.js lib that has _less lines than this readme™_.

It supports a tiny subset of the [json schema](http://json-schema.org/) specs. The main goal of this project is
to provide a nice and easy to follow implementation of a json validator. You may fork it and extend it as you please.

Release versioning follows [SemVer](http://semver.org/).

# Installation

```
$ npm install mt-json-validator
```

It is supported [Node.js] and bowser

# Example

```javascript
'use strict';

let validator = require('mt-json-validator');

let book_schema = {
  type: 'object',
  required: true,
  properties: {
    title: {
      type: 'string',
      required: true
    },
    author: {
      type: 'object',
      required: true,
      properties: {
        name: {
          type: 'string',
          required: true
        },
        age: {
          type: 'integer',
          required: true
        },
        city: {
          type: 'string'
        }
      }
    },
    related_titles: {
      type: 'array',
      required: true,
      items: {
        type: 'string'
      }
    }
  }
};

let data = {
  title: 'A Game of Thrones',
  author: {
    name: 'George R. R. Marti'
  },
  related_titles: [1, 2, 'A Song of Ice and Fire'],
  extra: 'this will get removed'
};

let res = validator(book_schema, data);

res.isValid;
// false

res.errors;
// {author.age: "is required", related_titles.0: 'type must be string', related_titles.1: 'type must be string'}

res.data;
// {title: 'A Game of Thrones', author: {name: 'George R. R. Marti'}, related_titles: ['A Song of Ice and Fire']}
```

# Running tests

```
$ npm run test
```

# Changelog

3.1.2: object create
3.1.1: add isArray fn
3.1.0: update version
3.0.2: fixed bug
3.0.1: support browser

2.0.1: add [number] and [boolen] types

## License

MIT

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