jsonman
v1.1.0
Published
Simplified JSON analyzer
Downloads
5
Maintainers
Readme
Simplified JSON analyzer
Install
$ yarn add jsonman
or
$ npm i jsonman
Usage
const jsonman = require('jsonman')
const schema = jsonman.analyzer({
string: '',
str: 'str',
number: 0,
num: 1,
boolean: false,
bool: true,
object: {},
obj: {
arr: [1, { num: 0 }]
},
array: [],
arr: [1, {
num: 1
}]
})
const data = {
str: '',
num: 0,
bool: false,
obj: { arr: [0, {}] },
arr: [0, { num: 0 }]
}
console.log(jsonman.validator(schema, data)) // true
API
type Types = 'object' | 'array' | 'number' | 'string' | 'boolean';
type SchemaObject = {
[index: string]: SchemaItem;
};
type SchemaItem = {
types: Types[];
unique?: boolean;
items?: SchemaItem[];
properties?: SchemaObject;
};
type DataObject = {
[index: string]: DataItem;
};
type DataItem = object | number | string | boolean;
type CanAnalyzed = {
(data: DataObject): SchemaObject;
(data: DataItem): SchemaItem;
};
validator: (schema: SchemaObject, data: DataObject) => boolean;
analyzer: CanAnalyzed;
License
MIT