# tiny-json-validator

> A simple and extensible json schema validator

Latest version **2.0.0** (published 2015-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install tiny-json-validator
pnpm add tiny-json-validator
yarn add tiny-json-validator
bun add tiny-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 | 2.0.0 |
| Published | 2015-11-22 |
| First published | 2015-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Esteban Castro Borsani |
| Maintainers | nitely |
| Keywords | jsonschema, json, validator |

## Links

- npm: https://www.npmjs.com/package/tiny-json-validator
- Repository: https://github.com/nitely/tiny-json-validator
- Issues: https://github.com/nitely/tiny-json-validator/issues
- npm.io page: https://npm.io/package/tiny-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

- 2.0.0 (latest) — 2015-11-22
- 1.0.0 — 2015-03-23

## README

# Tiny JSON validator

[![Build Status](https://img.shields.io/travis/nitely/tiny-json-validator/master.svg?style=flat-square)](https://travis-ci.org/nitely/tiny-json-validator)
[![npm](https://img.shields.io/npm/v/tiny-json-validator.svg?style=flat-square)](https://www.npmjs.com/package/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 tiny-json-validator
```

It is supported in all versions of [Node.js](https://nodejs.org) +4.2 without any flags.

# Example

```javascript
"use strict";

let validator = require('tiny-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

[changelog](https://github.com/nitely/tiny-json-validator/blob/master/CHANGES.md)

## License

MIT

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