🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@peculiar/json-schema

Package Overview
Dependencies
Maintainers
6
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@peculiar/json-schema

This package uses ES2015 decorators to simplify JSON schema creation and use

1.1.12
latest
Source
npm
Version published
Weekly downloads
2.8M
4.53%
Maintainers
6
Weekly downloads
 
Created

What is @peculiar/json-schema?

The @peculiar/json-schema package is a powerful tool for working with JSON schemas in JavaScript. It allows for serialization and deserialization of JavaScript objects based on JSON Schema definitions. This package is particularly useful for ensuring data integrity and for validating data structures in applications that heavily utilize JSON.

What are @peculiar/json-schema's main functionalities?

Serialization

This feature allows you to serialize JavaScript objects into JSON strings based on a defined JSON schema. It ensures that the serialized data adheres to the specified schema structure.

const { JsonParser } = require('@peculiar/json-schema');

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number' }
  }
};

const person = { name: 'John', age: 30 };
const serialized = JsonParser.serialize(person, schema);
console.log(serialized);

Deserialization

This feature enables the deserialization of JSON strings into JavaScript objects, validating against a JSON schema. It is useful for parsing and validating incoming JSON data to ensure it meets expected formats and constraints.

const { JsonParser } = require('@peculiar/json-schema');

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number', minimum: 18 }
  }
};

const jsonData = '{"name":"John","age":30}';
const deserialized = JsonParser.parse(jsonData, schema);
console.log(deserialized);

Other packages similar to @peculiar/json-schema

Keywords

json

FAQs

Package last updated on 22 Jul 2020

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