Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-my-json-valid

Package Overview
Dependencies
Maintainers
7
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-my-json-valid

A [JSONSchema](https://json-schema.org/) validator that uses code generation to be extremely fast.

  • 2.20.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
614K
decreased by-50.96%
Maintainers
7
Weekly downloads
 
Created

What is is-my-json-valid?

The is-my-json-valid npm package is a JSON schema validator that is fast and simple to use. It allows you to validate JSON data against a schema, ensuring that the data conforms to the expected structure and types.

What are is-my-json-valid's main functionalities?

Basic JSON Validation

This feature allows you to validate a simple JSON object against a schema. In this example, the schema expects an object with a string 'name' and a number 'age'. The provided JSON object meets these criteria, so the validation returns true.

const validator = require('is-my-json-valid');
const validate = validator({ type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' } } });
const valid = validate({ name: 'John', age: 30 });
console.log(valid); // true

Custom Error Messages

This feature provides detailed error messages when validation fails. In this example, the 'age' property is a string instead of a number, so the validation fails and the errors are logged.

const validator = require('is-my-json-valid');
const validate = validator({ type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' } } }, { verbose: true });
const valid = validate({ name: 'John', age: 'thirty' });
if (!valid) console.log(validate.errors);

Formats and Custom Formats

This feature allows you to use predefined formats like 'email' to validate specific types of strings. In this example, the 'email' property must be a valid email address.

const validator = require('is-my-json-valid');
const validate = validator({ type: 'object', properties: { email: { type: 'string', format: 'email' } } });
const valid = validate({ email: 'test@example.com' });
console.log(valid); // true

Other packages similar to is-my-json-valid

Keywords

FAQs

Package last updated on 10 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc