
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
json-schema-blocks
Advanced tools
Building blocks for human-friendly JSON-Schema definition.
// JSON example
const json = {
prop1: "value",
prop2: 2
}
// schema defined with blocks
const blocks = obj({
prop1: str(1),
prop2: num()
})
// generated JSON-Schema
const jsonSchema = {
type: "object",
properties: {
prop1: {
type: "string",
minLength: 1
},
prop2: {
type: "number"
}
},
required: ['prop1', 'prop2']
}
// String schema
str()
// Result
{
type: 'string'
}
// Minimum length: 1 char
str(1)
// Result
{
type: 'string'
}
// Minimum length: 1 char, maximum length: 10 chars
str(1, 10)
// Result
{
type: 'string',
minLength: 1,
maxLength: 10
}
// No minimum length, maximum length: 10 chars
str(null, 10)
// Result
{
type: 'string',
maxLength: 10
}
// Oprions can be passed "as is" also
str({maxLength: 10})
// Result
{
type: 'string',
maxLength: 10
}
// Number schema
num()
// Result
{
type: 'number'
}
// Minimum: 1
num(1)
// Result
{
type: 'number',
minimum: 1
}
// Minimum: 1, maximum: 10
num(1, 10)
// Result
{
type: 'number',
minumum: 1,
maximum: 10
}
// No minimum limit, maximum: 10
str(null, 10)
// Result
{
type: 'number',
maximum: 10
}
// Oprions can be passed "as is" also
str({maximum: 10})
// Result
{
type: 'number',
maximum: 10
}
Works same as num(), but with integar type
// Integer schema
int()
// Result
{
type: 'integer'
}
Common limitation for id in RDBS: should be >= 1
// shortcut to int(1)
id()
// Result
{
type: 'integer',
minimum: 1
}
// Boolean schema
bool()
// Result
{
type: 'boolean'
}
// Array of strings
arr(str())
// Result:
{
type: 'array',
items: {
type: 'string'
}
}
// Object
obj({
prop1: str()
})
// Result:
{
type: "object",
properties: {
prop1: {
type: "string"
}
},
required: ['prop1'] // keys are required by default
}
// Valid object example:
{
prop1: "value 1"
}
Required keys can be passed explicitly:
// Object with required key "prop1"
obj({
prop1: str(),
prop2: str()
}, {
required: ['prop1']
})
// Result:
{
type: "object",
properties: {
prop1: {
type: "string"
},
prop2: {
type: "string"
},
},
required: ['prop1']
}
// Valid objects example:
{
prop1: "value 1"
}
{
prop1: "value 1",
prop2: "value 2"
}
Optional keys can be passed explicitly:
// Object with optional key "prop1"
obj({
prop1: str(),
prop2: str()
}, {
required: ['prop2']
})
// Result:
{
type: "object",
properties: {
prop1: {
type: "string"
},
prop2: {
type: "string"
},
},
required: ['prop1']
}
// Valid objects example:
{
prop1: "value 1"
}
{
prop1: "value 1",
prop2: "value 2"
}
null is a type in JSON-Schema. It can be added to type via nullable helper.
// Object with optional key "prop1"
nullable(str())
// Result:
{
type: ["string", "null"]
}
Restricted set of string values can be defined with enumStr(...)
// Enum schema
enumStr('value1', 'value2')
// Result:
{
type: 'string',
enum: ['value1', 'value2']
}
FAQs
Building blocks for human-friendly JSON-Schema definitions
We found that json-schema-blocks 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.