# q-schema-validator

> JSON Schema validator for javascript

Latest version **0.0.4** (published 2019-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install q-schema-validator
pnpm add q-schema-validator
yarn add q-schema-validator
bun add q-schema-validator
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-01-17 |
| First published | 2019-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 199.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | yaotaiyang |
| Maintainers | yaotaiyang |

## Links

- npm: https://www.npmjs.com/package/q-schema-validator
- Homepage: https://github.com/yaotaiyang/q-schema-validator
- Issues: https://github.com/yaotaiyang/q-schema-validator
- npm.io page: https://npm.io/package/q-schema-validator

## Recent versions

- 0.0.4 (latest) — 2019-01-17
- 0.0.3 — 2019-01-16
- 0.0.2 — 2019-01-12
- 0.0.1 — 2019-01-12

## README

# q-schema-validator
JSON Schema validator for javascript

### download && test demo

```
git clone git@github.com:yaotaiyang/q-schema-validator.git

npm install

npm run dev
```
open browser http://localhost:9092/


### install

```
npm install q-schema-validator --save

```

### use as module

``` javascript
import JSONSchemaValidator from 'q-schema-validator'

let schema = {
  "type": "object",
  "properties": {
    "a": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "ac": {
            "type": "number"
          },
          "g": {
            "type": "string"
          }
        },
        "required": [ 'g' ]
      }
    },
    "b": {
      "type": [ 'number' ]
    }
  },
  "required": [ "b", "f" ]
}
let data = {
  "a": [ {
    "ac": '11'
  } ],
  "b": '111'
}

var validator = new JSONSchemaValidator();
let res = validator.validate(data, schema);
console.log(res);

[
  {
    "path": "a.0.ac",
    "message": "Expected number but got string."
  },
  {
    "path": "a.0.g",
    "message": "Missing required property g."
  },
  {
    "path": "b",
    "message": "Expected number but got string."
  }
]

```

### use in browser

``` html
<script src="https://unpkg.com/q-schema-validator/lib/index.js"></script>
```
``` javascript
let schema = {
  "type": "object",
  "properties": {
    "a": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "ac": {
            "type": "number"
          },
          "g": {
            "type": "string"
          }
        },
        "required": [ 'g' ]
      }
    },
    "b": {
      "type": [ 'number' ]
    }
  },
  "required": [ "b", "f" ]
}
let data = {
  "a": [ {
    "ac": '11'
  } ],
  "b": '111'
}

var validator = new JSONSchemaValidator();
let res = validator.validate(data, schema);
console.log(validator);
console.log(JSON.stringify(res, null, 2));


[
  {
    "path": "a.0.ac",
    "message": "Expected number but got string."
  },
  {
    "path": "a.0.g",
    "message": "Missing required property g."
  },
  {
    "path": "b",
    "message": "Expected number but got string."
  }
]

```

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