Socket
Socket
Sign inDemoInstall

tv4

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tv4

A public domain JSON Schema validator for JavaScript


Version published
Weekly downloads
2.1M
decreased by-0.1%
Maintainers
2
Weekly downloads
 
Created

What is tv4?

The tv4 npm package is a JSON Schema validator. It allows you to validate JSON data against a JSON Schema to ensure that the data structure conforms to a specified format. This is particularly useful for data validation, configuration management, and ensuring data integrity across systems.

What are tv4's main functionalities?

Basic Validation

This feature allows you to validate a simple piece of data against a schema. In this example, a string is validated against a schema that requires a string type, resulting in a successful validation.

{"var tv4 = require('tv4');\nvar schema = {\"type\": \"string\"};\nvar result = tv4.validateResult('I am a string', schema);\nconsole.log(result.valid); // true"}

Complex Schema Validation

This feature demonstrates validating a more complex JSON object against a detailed schema. The schema specifies that the object must have a 'name' property of type string and an 'age' property of type integer with a minimum value of 0. The validation passes as the data meets these criteria.

{"var tv4 = require('tv4');\nvar schema = {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\", \"minimum\": 0}}};\nvar data = {\"name\": \"John Doe\", \"age\": 30};\nvar result = tv4.validateResult(data, schema);\nconsole.log(result.valid); // true"}

Validation with Error Reporting

This feature showcases how tv4 can report errors when validation fails. In this example, attempting to validate a string against a schema that expects a number results in a validation error, which is then logged.

{"var tv4 = require('tv4');\nvar schema = {\"type\": \"number\"};\nvar result = tv4.validateResult('not a number', schema);\nif (!result.valid) {\n  console.error(result.error);\n}"}

Other packages similar to tv4

Keywords

FAQs

Package last updated on 20 Mar 2017

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