Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vasuvanka committed Nov 15, 2020
1 parent 63611b9 commit 5ae0c9b
Showing 1 changed file with 80 additions and 39 deletions.
119 changes: 80 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# json-validator
# json-validator for Node.js / deno

Json Validator - validates a json object against defined schema.

## Install
Expand All @@ -9,55 +10,95 @@ npm install @vasuvanka/json-validator

## Docs

* API Documentation: https://vasuvanka.github.io/json-validator

## Example
- API Documentation: https://vasuvanka.github.io/json-validator

```js
const {
validate
} = require('@vasuvanka/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},
name: {
type: String,
},
phone: { type: Number },
isLoggedIn: { type: Boolean },
address: {
line: {
add: [{ type: Number }],
},
list: [{type:String}]
}
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
name: "Hello",
phone: 88010000000,
address: {
line: {
add: [1],
},
isLoggedIn: false,
list: ['hello','world']
street: "streetlk111",
city: "some city",
pincode: 453672,
},
isLoggedIn: false,
list: ["hello", "world"],
};
const error = validate(body, bodySchema, { allowUnknown: true });
console.log(error);

}
const error = validate(body,bodySchema)
console.log(error)
const err = validate(body, bodySchema, { allowUnknown: false });
console.log(err);
```

## Node.js Example

const err = validate(body,bodySchema,{allowUnknown: false})
console.log(err)
```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.
## Free software,hell ya.

0 comments on commit 5ae0c9b

Please sign in to comment.