
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
@alexkuz/json-schema-default-instance
Advanced tools
Creates an object as an instance of the given schema using its default properties.
Creates an object as an instance of the given schema using its default
properties.
id
.$ref
and allOf
.default
, unlessrequiredOnly = true
, ignores properties that are not listed in the required
array (see example below).Install with npm install --save json-schema-default-instance
See test/test.js
for an example with $ref
and allOf
.
Simple example below:
const {Instantiator} = require('json-schema-default-instance');
const mySchemas = [
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "theSchemaId",
"type": "object",
"required": [
"firstName",
"lastName"
],
"properties": {
"firstName": {
"type": "string",
"default": "Foo"
},
"lastName": {
"type": "string",
"default": "Bar"
},
"optionalProperty": {
"type": "string",
"default": "Hello"
}
}
}
]
/* Instantiate with all properties */
let ins = new Instantiator(mySchemas);
let myDefaultInstance = ins.instantiate('theSchemaId');
console.log(myDefaultInstance);
// => { firstName: 'Foo', lastName: 'Bar', optionalProperty: 'Hello' }
/* This time, only with `required` properties */
ins.requiredOnly = true;
let myRequiredInstance = ins.instantiate('theSchemaId');
console.log(myRequiredInstance);
// => { firstName: 'Foo', lastName: 'Bar' }
Relies heavily on Ajv
for caching and lookup by ref, even though no validation is done here.
Ajv: Another JSON Schema Validator
Ajv
does have its own useDefaults
option which can be used instead of this package,
but it does not support default
keywords in subschemas or allOf
.
If you don't need allOf
, just use Ajv
directly (see Ajv assigning-defaults and related discussion).
Need help understanding JSON Schema? I would recommend the Space Telescope Science Institute's Understanding JSON Schema
Public Domain
FAQs
Creates an object as an instance of the given schema using its default properties.
We found that @alexkuz/json-schema-default-instance demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.