<img align="right" alt="Ajv logo" width="160" src="http://epoberezkin.github.io/ajv/images/ajv_logo.png">
# Ajv: Another JSON Schema Validator
The fastest JSON Schema validator for node.js and browser. Supports [v5 proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals).
[![Build Status](https://travis-ci.org/epoberezkin/ajv.svg?branch=master)](https://travis-ci.org/epoberezkin/ajv)
[![npm version](https://badge.fury.io/js/ajv.svg)](https://www.npmjs.com/package/ajv)
[![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv)
[![Code Climate](https://codeclimate.com/github/epoberezkin/ajv/badges/gpa.svg)](https://codeclimate.com/github/epoberezkin/ajv)
[![Coverage Status](https://coveralls.io/repos/epoberezkin/ajv/badge.svg?branch=master&service=github)](https://coveralls.io/github/epoberezkin/ajv?branch=master)
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)
__Please note__: You can start using NEW beta version [5.0.4](https://github.com/epoberezkin/ajv/releases/tag/5.0.4-beta.3) (see [migration guide from 4.x.x](https://github.com/epoberezkin/ajv/releases/tag/5.0.1-beta.0)) with the support of JSON-Schema draft-06 (not officially published yet): `npm install ajv@^5.0.4-beta`.
Also see [docs](https://github.com/epoberezkin/ajv/tree/5.0.4-beta.3) for 5.0.4.
## Contents
- [Performance](#performance)
- [Features](#features)
- [Getting started](#getting-started)
- [Frequently Asked Questions](https://github.com/epoberezkin/ajv/blob/master/FAQ.md)
- [Using in browser](#using-in-browser)
- [Command line interface](#command-line-interface)
- Validation
- [Keywords](#validation-keywords)
- [Formats](#formats)
- [$data reference](#data-reference)
- NEW: [$merge and $patch keywords](#merge-and-patch-keywords)
- [Defining custom keywords](#defining-custom-keywords)
- [Asynchronous schema compilation](#asynchronous-compilation)
- [Asynchronous validation](#asynchronous-validation)
- Modifying data during validation
- [Filtering data](#filtering-data)
- [Assigning defaults](#assigning-defaults)
- [Coercing data types](#coercing-data-types)
- API
- [Methods](#api)
- [Options](#options)
- [Validation errors](#validation-errors)
- [Related packages](#related-packages)
- [Packages using Ajv](#some-packages-using-ajv)
- [Tests, Contributing, History, License](#tests)
## Performance
Ajv generates code using [doT templates](https://github.com/olado/doT) to turn JSON schemas into super-fast validation functions that are efficient for v8 optimization.
Currently Ajv is the fastest and the most standard compliant validator according to these benchmarks:
- [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark) - 50% faster than the second place
- [jsck benchmark](https://github.com/pandastrike/jsck#benchmarks) - 20-190% faster
- [z-schema benchmark](https://rawgit.com/zaggino/z-schema/master/benchmark/results.html)
- [themis benchmark](https://cdn.rawgit.com/playlyfe/themis/master/benchmark/results.html)
Performace of different validators by [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark):
[![performance](https://chart.googleapis.com/chart?chxt=x,y&cht=bhs&chco=76A4FB&chls=2.0&chbh=32,4,1&chs=600x416&chxl=-1:%7Cajv%7Cis-my-json-valid%7Cjsen%7Cschemasaurus%7Cthemis%7Cz-schema%7Cjsck%7Cjsonschema%7Cskeemas%7Ctv4%7Cjayschema&chd=t:100,68,61,22.8,17.6,6.6,2.7,0.9,0.7,0.4,0.1)](https://github.com/ebdrup/json-schema-benchmark/blob/master/README.md#performance)
## Features
- Ajv implements full [JSON Schema draft 4](http://json-schema.org/) standard:
- all validation keywords (see [JSON-Schema validation keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md))
- full support of remote refs (remote schemas have to be added with `addSchema` or compiled to be available)
- support of circular references between schemas
- correct string lengths for strings with unicode pairs (can be turned off)
- [formats](#formats) defined by JSON Schema draft 4 standard and custom formats (can be turned off)
- [validates schemas against meta-schema](#api-validateschema)
- supports [browsers](#using-in-browser) and nodejs 0.10-6.x
- [asynchronous loading](#asynchronous-compilation) of referenced schemas during compilation
- "All errors" validation mode with [option allErrors](#options)
- [error messages with parameters](#validation-errors) describing error reasons to allow creating custom error messages
- i18n error messages support with [ajv-i18n](https://github.com/epoberezkin/ajv-i18n) package
- [filtering data](#filtering-data) from additional properties
- [assigning defaults](#assigning-defaults) to missing properties and items
- [coercing data](#coercing-data-types) to the types specified in `type` keywords
- [custom keywords](#defining-custom-keywords)
- keywords `switch`, `constant`, `contains`, `patternGroups`, `patternRequired`, `formatMaximum` / `formatMinimum` and `formatExclusiveMaximum` / `formatExclusiveMinimum` from [JSON-schema v5 proposals](https://github.com/json-schema/json-schema/wiki/v5-Proposals) with [option v5](#options)
- [v5 meta-schema](https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#) for schemas using v5 keywords
- [v5 $data reference](#data-reference) to use values from the validated data as values for the schema keywords
- [asynchronous validation](#asynchronous-validation) of custom formats and keywords
Currently Ajv is the only validator that passes all the tests from [JSON Schema Test Suite](https://github.com/json-schema/JSON-Schema-Test-Suite) (according to [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark), apart from the test that requires that `1.0` is not an integer that is impossible to satisfy in JavaScript).
## Install
```
npm install ajv
```
To install a stable beta version [5.0.4](https://github.com/epoberezkin/ajv/releases/tag/5.0.4-beta.3) (see [migration guide from 4.x.x](https://github.com/epoberezkin/ajv/releases/tag/5.0.1-beta.0)):
```
npm install ajv@^5.0.4-beta
```
## <a name="usage"></a>Getting started
Try it in the node REPL: https://tonicdev.com/npm/ajv
The fastest validation call:
```javascript
var Ajv = require('ajv');
var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
var validate = ajv.compile(schema);
var valid = validate(data);
if (!valid) console.log(validate.errors);
```
or with less code
```javascript
// ...
var valid = ajv.validate(schema, data);
if (!valid) console.log(ajv.errors);
// ...
```
or
```javascript
// ...
ajv.addSchema(schema, 'mySchema');
var valid = ajv.validate('mySchema', data);
if (!valid) console.log(ajv.errorsText());
// ...
```
See [API](#api) and [Options](#options) for more details.
Ajv compiles schemas to functions and caches them in all cases (using schema stringified with [json-stable-stringify](https://github.com/substack/json-stable-stringify) as a key), so that the next time the same schema is used (not necessarily the same object instance) it won't be compiled again.
The best performance is achieved when using compiled functions returned by `compile` or `getSchema` methods (there is no additional function call).
__Please note__: every time validation function or `ajv.validate` are called `errors` property is overwritten. You need to copy `errors` array reference to another variable if you want to use it later (e.g., in the callback). See [Validation errors](#validation-errors)
## Using in browser
You can require Ajv directly from the code you browserify - in this case Ajv will be a part of your bundle.
If you need to use Ajv in several bundles you can create a separate UMD bundle using `npm run bundle` script (thanks to [siddo420](https://github.com/siddo420)).
Then you need to load Ajv in the browser:
```html
<script src="ajv.min.js"></script>
```
This bundle can be used with diffe
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
springboot微信点餐系统代码 (12783个子文件)
almond.0 2KB
0051889206284074e5f45bdeec26db2aaec3e1 190B
0236d42a413ee9a35436b1f31fd8baf9197e48 148B
032781e7055cc5d56c684902c9edf191e8ee5d 54B
0568416d1e2a5b2ce78d6875e0f73bcce7c417 145B
0678bb2863ddb587a84cef9b4abe8e1a7536f6 464B
0aaf32c4bac422c823d9f7a2c64c77be382caf 373B
sshpk-conv.1 4KB
he.1 3KB
jsesc.1 3KB
jsesc.1 3KB
sshpk-sign.1 2KB
sshpk-verify.1 2KB
cssesc.1 2KB
almond.1 558B
1560d81433725dc49e535f4311cc5f962258f5 148B
16e95479bf4dd63c7d353fb012af70d912c06e 2KB
172a64d20ef8355d1813fb9447adb39df2552b 351B
19aec27efc17e26ca9fc58b3dfa70e1b4bb347 175B
19bcec3e802fa3b9ddad26260ec25a12c7864a 464B
1cfecb763bc6fb0e27d62227b66335de813063 3KB
1f68160c23ca4c269677f2a05b4b1ddd8529aa 421B
1fe2247e62c4970e5cda832ca4d6fc384ab282 464B
2542399830105dce1db5a9b11469afc27d6e34 2KB
285109942973b1ae28a35ebc8bb9ead6eef818 286B
28975ab9cf7d26bb96dd098e641e7ed170ba6c 210B
28d1466dcef5c77b88b6c7ec42b0977508c1af 194B
293f59c2c94ef5c1a3093fab8640a64bec55e9 84B
2b21a80cb0f0831f2b20dc0c269f6289eec5b4 84B
2f94b6d66979772b215c86fb8d8f13a9089a0f 3KB
2fcc9bd2d69eac22efbe86442d65a7e97a6a87 54B
34f9ab535a25ea26879fe2134cb792a307a5b4 2KB
35c8037730b33459ee32ce5c4613d03a11d975 352B
3884a1d16162e62d700206e8d8256afb646bcf 286B
39a1ba7aeefd6b340c6f223409a8e5a9d2e4f7 209B
3b9eed3bcffa8ab4a516dee7c9613c54d936e7 83B
4015209c0613f5f72d390a16851afe9be73883 165B
40711475d72b97603b85eb480079dcddb7ad14 352B
41edc2f01122ecc7327512917af86633cb5005 193B
420ce219a5abde2ee59109c1df513b73c159a1 148B
4362000fceaeb14445608119e57824342c393d 2KB
4530b26cc4a79e0d2a2f3451b42421695aea88 84B
4b46f8d1ee5d91b9d2b6882f2a2350375bc5ea 979B
4fde6ef0289b02fac94840c06447ba997142e3 2KB
55eeaf2f62f555a0165d8cc8669681b15375af 941B
5659e1be4b85b00ce099318b9197d8b8b5551b 1KB
58985094c05d238153eb413b2909017b1a3f06 373B
59b435d1532fced86fbaf6c743859128c501f7 373B
5b7de8853358dcc3929d8906bfe151fe9a5001 3KB
65e2f187ba48417e795efb9b7134b341fdadfe 465B
67a7195aa37ad082f8c94e30f7d982adf35f58 148B
698b14c5bf6c7a497b641eb47cf7cc258ad42d 148B
69d59c2931d29a31c1340ff208721dd9340b71 465B
6a621d79e1374f7d909837cf5ba8d37124a506 286B
6d9ea0f9e704fc0389fe64073444f26a915bc9 689B
6e00f597967e21b437b76a5821cd2080e29004 610B
727fd153df43f5f372d6509db21a579f8f2f62 5KB
7376fe003cbf1ed49629d46fd3133c6d3e7423 464B
73a5ee500ce560734399962497ef10e5b96b9c 493B
74678a257b19258c7d47990546a81534eaae5e 2KB
756ce9e3d9e2118e499d66f8e8eabccde88c38 192B
763b0b72faadea7a35d9c02a89a67b43e736d0 663B
768f941870acc4a56f8b7bb2a481b51554fc98 2KB
7870bf5ca0025dcff65cf3c3263fdf6044cf56 175B
793da269e132d2f5d6431505d0a8f3f1e33f8e 54B
79e55b06b2e5cc36c673f7bda1c19659629783 148B
7d4e31ff071987d0ce81737e8ded4a6b5cfa47 2KB
81ecceedba20eec83b8afe7bc876e7a395645c 493B
8356bb5cc7b497ade71929e459840a9ff0b38b 373B
8360d47a52cfc163f920245114bb1123e559f7 352B
841c5cbc45b9a524ba2e63fae38594b69f1899 287B
8434961784d94f5a7b3065599aa2ee1cd9eb5a 464B
844ebec79bebcb2f93e8915ae1768a12baee4f 3KB
8635ad75f49415637eaba84ac02e760c4014c5 464B
870a7798729ceb92835a4ff8566d71d80ace0e 3KB
87e3902aa6afec27d25fd4945f556462425f4f 202B
885e6ed2ed7f5cffde82db94052dbf5a676a29 373B
88adb96bf01fbd849bdbe4689e542ee0d5da23 7KB
8a3f4467a519fc8cab5a041dc5cdfbda35448c 149B
8c4d72926f5b2dd21366edcc0f58126fe4e036 54B
9070e9d1a6b84add8472c7b6bb3a8d2dcd69f8 85B
916ce00a91a8dedbe39ab719f1fdfa4388fcf6 7KB
9270ea246494536fd7d40d542443d2d77660a7 373B
92ccc533b23de18293741c71b44e9335e1e92f 2KB
9359fc0a54d1bfee691f0e4486d8abcbb4c5a5 85B
95eaa02870ccc02b9a47779f6a0c1bdee5c1eb 1KB
963faffd885e3802be78a158c7e9d07543d3d0 3KB
96c9108d691920f016ff32be96731f4daa60c3 148B
97779a4d7ebbe1e5705d3e602fa8f46c5c68ad 144B
9bd6b85d7fca40f76e3c0ed26414fecc7a1b23 85B
9bea9a1b255de1b6ac8a5e05f5c865b026e6d0 465B
9fb50bc7902fa57a77d0a83fc8d42f3d7d9215 1KB
a0270f607d3d8467f35a8192a7684873e0cee6 3KB
a04fa8eb1c819e15d94d49be5dbe086a63897f 465B
a65126e5cdde155066a2e5cc32d4e96334bde7 144B
a7fd59e38033c12bbd9750fdde8ef748cebd57 808B
acaa7676541650dafb1e3b9d0e7a15d2944377 465B
acorn 2KB
acorn 2KB
acorn 2KB
共 12783 条
- 1
- 2
- 3
- 4
- 5
- 6
- 128
资源评论
- qq_230559112018-01-28看看,是否自己想要的
- liuhengfu2018-01-24刚刚下载,还没有来得急看
- guoheping1132018-08-14只有前端代码,没用,浪费资源分
- bjx08202018-01-30只有前端代码,没用,浪费资源分
Always_Do_The_Best
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功