Skip to main content
Version: v2

JSONSchemer

Transpiles a DynamoDB-Toolbox schema into a standard JSON Schema describing its formatted (i.e. read) value.

This is useful for OpenAPI specs, form generation, LLM/MCP tool definitions, or any tooling that consumes JSON Schema.

Like the ZodSchemer, the transpilation itself is type-safe, which means the resulting JSON Schema type can be introspected and type inference is preserved:

import { JSONSchemer } from 'dynamodb-toolbox/schema/actions/jsonSchemer'

const pokemonSchema = item({
pokemonId: string(),
level: number(),
pokeType: string()
.enum('fire', 'water', 'grass')
.optional()
})

const jsonSchema = pokemonSchema
.build(JSONSchemer)
.formattedValueSchema()
// =>
// {
// type: 'object',
// properties: {
// pokemonId: { type: 'string' },
// level: { type: 'number' },
// pokeType: { type: 'string' }
// },
// required: ['pokemonId', 'level']
// }
note

The generated JSON Schema describes the formatted value, so it mirrors what the Formatter action returns (not the raw saved shape). hidden attributes are stripped, and optional attributes are excluded from required.

Methods​

formattedValueSchema()​

() => FormattedValueJSONSchema<SCHEMA>

Returns the JSON Schema of the schema's formatted value:

const jsonSchema = pokemonSchema
.build(JSONSchemer)
.formattedValueSchema()

Only attributes that appear in the formatted value are included. item and map schemas produce type: 'object' (with additionalProperties: false when strict), list/set/tuple produce type: 'array', record produces type: 'object' with propertyNames/additionalProperties, and anyOf produces an anyOf union.