All Projects → yusufnb → Verify Json

yusufnb / Verify Json

Licence: mit
verify-json

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Verify Json

React Jsonschema Form
A React component for building Web forms from JSON Schema.
Stars: ✭ 10,870 (+5125.96%)
Mutual labels:  json-schema, json
Libvirt Hook Qemu
Libvirt hook for setting up iptables port-forwarding rules when using NAT-ed networking.
Stars: ✭ 137 (-34.13%)
Mutual labels:  json-schema, json
Schema Registry
Confluent Schema Registry for Kafka
Stars: ✭ 1,647 (+691.83%)
Mutual labels:  json-schema, json
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-65.87%)
Mutual labels:  restful-api, json
Staticjson
Fast, direct and static typed parsing of JSON with C++
Stars: ✭ 177 (-14.9%)
Mutual labels:  json-schema, json
Swurg
Parse OpenAPI documents into Burp Suite for automating OpenAPI-based APIs security assessments (approved by PortSwigger for inclusion in their official BApp Store).
Stars: ✭ 94 (-54.81%)
Mutual labels:  restful-api, json
Typedload
Python library to load dynamically typed data into statically typed data structures
Stars: ✭ 120 (-42.31%)
Mutual labels:  json-schema, json
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-76.44%)
Mutual labels:  restful-api, json
Newtonsoft.json.schema
Json.NET Schema is a powerful, complete and easy to use JSON Schema framework for .NET
Stars: ✭ 167 (-19.71%)
Mutual labels:  json-schema, json
Go Jsonschema
A tool to generate Go data types from JSON Schema definitions.
Stars: ✭ 164 (-21.15%)
Mutual labels:  json-schema, json
Avocado
Strongly-typed MongoDB driver for Rust
Stars: ✭ 70 (-66.35%)
Mutual labels:  json-schema, json
Jsonform
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
Stars: ✭ 2,416 (+1061.54%)
Mutual labels:  json-schema, json
Schemasafe
A reasonably safe JSON Schema validator with draft-04/06/07/2019-09 support.
Stars: ✭ 67 (-67.79%)
Mutual labels:  json-schema, json
Json Node Normalizer
'json-node-normalizer' - NodeJS module that normalize json data types from json schema specifications.
Stars: ✭ 105 (-49.52%)
Mutual labels:  json-schema, json
Jsonschema Key Compression
Compress json-data based on its json-schema while still having valid json
Stars: ✭ 59 (-71.63%)
Mutual labels:  json-schema, json
Npoint
JSON storage bins with schema validation
Stars: ✭ 116 (-44.23%)
Mutual labels:  json-schema, json
Oakdex Pokedex
Ruby Gem and Node Package for comprehensive Generation 1-7 Pokedex data, including 809 Pokémon, uses JSON schemas to verify the data
Stars: ✭ 44 (-78.85%)
Mutual labels:  json-schema, json
Univalue
High performance RAII C++ JSON library and universal value object class
Stars: ✭ 46 (-77.88%)
Mutual labels:  json-schema, json
Bricks
A standard library for microservices.
Stars: ✭ 142 (-31.73%)
Mutual labels:  restful-api, json
Json Schema Spec
The JSON Schema I-D sources
Stars: ✭ 2,441 (+1073.56%)
Mutual labels:  json-schema, json

Verify JSON

Library to verify JSON structure easily using a lightweight JSON schema syntax

About

This project results from my need to verify JSON schema in a lightweight manner, without the need for an extensive definition and development code.

The schema syntax is minimalist and extremely easy to write.

Installation

npm install -s verify-json

const verify = require('verify-json')

import verify from 'verify-json';

Example

const { verify } = require("verify-json");

let json = {
  markers: [
    {
      stars: 5,
      name: 'Rixos The Palm Dubai',
      location: [25.1212, 55.1535],
      favorite: true,
      color: 'red',
    },
    {
      stars: 4,
      name: 'Shangri-La Hotel',
      location: [25.2084, 55.2719],
      color: 'blue',
    },
  ],
};

// <key>:<validator>
// <key>:?<validator> - uses ? for optional
// <key> - required non null attribute of any type
// Skip all the quotations
const schema = `{markers: [{
      stars:i,
      name:string,
      location:[:lat,:long],
      favorite:?b,
      color:color
  }]
}`;

// customValidators are optional. See built-in validators.
const customValidators = {
  lat: (val) => val >= -90 && val <= 90,
  long: (val) => val >= -180 && val <= 180,
  color: (val, args) => {
    // demonstrating conditional validations. args = { json, path, parent }
    return (args.parent.stars === 5 && val === 'red') || (args.parent.stars === 4 && val === 'blue');
  },
};

let result = verify(json, schema, customValidators);

console.log(result); // true

json.markers[0].location[0] = 1000;
json.markers[0].color = 'blue';
try {
  verify(json, schema, customValidators);
} catch (error) {
  console.log('error', error); // json.markers.0.location.0: validation failed, json.markers.0.color: validation failed
}


Built-in Validators

Following validators are built in and can be used directly -

{
    string    : _.isString,
    s         : _.isString,      // alias for string
    number    : _.isNumber,
    n         : _.isNumber,      // alias for number
    boolean   : _.isBoolean,
    b         : _.isBoolean,     // alias for boolean
    integer   : _.isInteger,
    i         : _.isInteger,     // alias for integer
}

Use as a mixin

Since lodash is a dependency, this method is also exposed as a lodash mixin. Once imported anywhere, you can simply use _.verify to access it.

_.verify(json, schema, customValidators)

License

MIT © Yusuf Bhabhrawala

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].