https://github.com/vasuvanka/json-validator
Json Validator
https://github.com/vasuvanka/json-validator
body json-validator request schema-validator validator
Last synced: 5 months ago
JSON representation
Json Validator
- Host: GitHub
- URL: https://github.com/vasuvanka/json-validator
- Owner: vasuvanka
- License: mit
- Created: 2020-04-05T07:58:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T16:19:19.000Z (over 3 years ago)
- Last Synced: 2025-11-23T17:05:21.544Z (7 months ago)
- Topics: body, json-validator, request, schema-validator, validator
- Language: TypeScript
- Homepage: https://vasuvanka.github.io/json-validator
- Size: 1.05 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-validator for Node.js / deno
Json Validator - validates a json object against defined schema.
## Install
```
npm install @vasuvanka/json-validator
```
## Docs
- API Documentation: https://vasuvanka.github.io/json-validator
## Deno Example
```ts
import { validate } from "https://deno.land/x/jsonvalidator/index.ts";
const bodySchema = {
name: {
type: String,
},
phone: { type: Number },
isLoggedIn: { type: Boolean },
address: {
line: {
add: [{ type: Number }],
},
street: { type: String },
city: { type: String },
pincode: { type: Number },
},
list: [{ type: String }],
};
const body = {
name: "Hello",
phone: 88010000000,
address: {
line: {
add: [1],
},
street: "streetlk111",
city: "some city",
pincode: 453672,
},
isLoggedIn: false,
list: ["hello", "world"],
};
const error = validate(body, bodySchema, { allowUnknown: true });
console.log(error);
const err = validate(body, bodySchema, { allowUnknown: false });
console.log(err);
```
## Node.js Example
```js
const { validate } = require("@vasuvanka/json-validator");
const bodySchema = {
name: {
type: String,
},
phone: { type: Number },
isLoggedIn: { type: Boolean },
address: {
line: {
add: [{ type: Number }],
},
street: { type: String },
city: { type: String },
pincode: { type: Number },
},
list: [{ type: String }],
};
const body = {
name: "Hello",
phone: 88010000000,
address: {
line: {
add: [1],
},
street: "streetlk111",
city: "some city",
pincode: 453672,
},
isLoggedIn: false,
list: ["hello", "world"],
};
const error = validate(body, bodySchema);
console.log(error);
const err = validate(body, bodySchema, { allowUnknown: false });
console.log(err);
```
## LICENCE
MIT
## Free software,hell ya.