Registry / devops / json-schema-shorthand

json-schema-shorthand

JSON →
library3.1.1jsnpmunverified

JavaScript library v3.1.1 providing compact shorthand syntax for JSON Schema definitions. Transforms string types, references (local with #, external with $), and shorthand functions into full schema objects. Supports all major JSON Schema constructs: object, array, primitive types, composition (allOf/oneOf/anyOf), not, and nested references. Includes TypeScript type definitions for schema validation. Active development with regular releases; minimal dependencies. Differentiator: reduces schema boilerplate significantly while maintaining full JSON Schema compatibility.

npm install json-schema-shorthand
INSTALL
IMPORT
SIG · JSON-SCHEMA-SHORTH
J
json-schema-shorthand
devopsjavascriptv3.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (shorthand)
import shorthand from 'json-schema-shorthand'
const shorthand = require('json-schema-shorthand')
Package exports default function `shorthand`; named imports also available. ESM-only since v3.
named functions (number, string, etc.)
import { number, string, object } from 'json-schema-shorthand'
import { j } from 'json-schema-shorthand'
Named exports are individual functions; namespace import `import * as j from '...'` works but direct named imports are encouraged for tree-shaking.
array
import { array } from 'json-schema-shorthand'
import { array } from 'json-schema-shorthand'; array('string') // OK, but note: no default array shorthand
`array` is a function, not a string shorthand. Always used with parentheses.
object
import { object } from 'json-schema-shorthand'
const { object } = require('json-schema-shorthand')
CommonJS require works but `import` is preferred. The `object` function has optional first argument for description.

Demonstrates basic usage: creating a JSON Schema with string shorthands in object properties, and using helper functions with optional description and extra properties.

import shorthand, { number, string, object, array } from 'json-schema-shorthand'; // Using string shorthand in object properties const schema1 = shorthand({ object: { name: 'string', age: 'number', tags: { object: { primary: 'string' } } } }); // Using helper functions const schema2 = object( { foo: string('description for foo', { default: 'bar' }) }, { description: 'My schema' } ); console.log(schema1); console.log(schema2);
Debug
Known issues
gotchaString type `integer` is valid shorthand; use `'integer'` string (not `'number'`) to get integer specialization.
fix
Use string literal `'integer'` where you want integer-typed properties, not `'number'`.
affects: >=1.0
gotchaProperty names starting with `#` or `$` are interpreted as references, not as type strings.
fix
If your property key intentionally starts with `#` or `$`, escape by using explicit `{ type: '...', $ref: undefined }` or use the `shorthand()` function only on the value, not the key.
affects: >=1.0
gotchaThe `object` shorthand function has optional description as first argument; omitting it may lead to unexpected argument binding if you supply extra schema.
fix
Always pass description as a string (or `undefined`) if you intend to pass extra schema as second argument: `object(undefined, { additionalProperties: false })`.
affects: >=1.0
deprecatedDefault export `shorthand` is deprecated in favor of named functions in some documentation, but still works.
fix
Use named imports: `import { shorthand } from 'json-schema-shorthand'` or `import shorthand from 'json-schema-shorthand'` (both work).
affects: >=3.0
gotchaShorthand expansion does not deeply transform nested arrays of schemas (e.g., inside `items` of a property that is itself an array).
fix
Manually expand nested arrays using `array()` function or ensure the inner schemas are already expanded.
affects: >=1.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Trying to use ESM `import` in a CommonJS file or without proper package.json type: module.
fix
Add `"type": "module"` to package.json, or use `const shorthand = require('json-schema-shorthand')`.
TypeError: shorthand is not a function
Default import not recognized (wrong import style).
fix
Use `import shorthand from 'json-schema-shorthand'` (ESM) or `const shorthand = require('json-schema-shorthand').default` (CommonJS).
Uncaught TypeError: object(...) is not a function
Incorrectly importing named function as default.
fix
Use `import { object } from 'json-schema-shorthand'`.
Upgrade
Version history
3.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
json-schema-shorthand — npm install json-schema-shorthand · libregistry