Skip to content

JsonSchema

Defined in: extract/schema.ts:708

JSON Schema utilities for extraction specs.

Provides static methods to derive JSON Schema from extraction specs.

new JsonSchema(): JsonSchema

JsonSchema

static output(source, options?): JsonSchemaObject

Defined in: extract/schema.ts:747

Generates a JSON Schema describing the output shape produced by a spec. Works statically without executing against data.

Use cases:

  • Generate API contracts / OpenAPI schemas
  • Generate TypeScript types
  • Document output structure

Spec

A Spec or a compiled Plan

JsonSchemaOptions

Optional schema generation options

JsonSchemaObject

JSON Schema describing the output structure

// From a Spec
const spec = extract($ => ({
name: $.get('user').get('name').string(),
age: $.get('user').get('age').number(),
}))
const schema = JsonSchema.output(spec)
// From a Plan with options
const plan = new Planner()
.in(loadFile('data.json'))
.mapIn(parseJson())
.emit((out, $) => out
.add('name', $.get('name').string())
.add('age', $.get('age').number())
)
.compile()
const schema = JsonSchema.output(plan, {
id: 'https://example.com/schema',
title: 'User',
deduplicate: true,
})

static output(source, options?): JsonSchemaObject

Defined in: extract/schema.ts:748

Generates a JSON Schema describing the output shape produced by a spec. Works statically without executing against data.

Use cases:

  • Generate API contracts / OpenAPI schemas
  • Generate TypeScript types
  • Document output structure

Plan<unknown>

A Spec or a compiled Plan

JsonSchemaOptions

Optional schema generation options

JsonSchemaObject

JSON Schema describing the output structure

// From a Spec
const spec = extract($ => ({
name: $.get('user').get('name').string(),
age: $.get('user').get('age').number(),
}))
const schema = JsonSchema.output(spec)
// From a Plan with options
const plan = new Planner()
.in(loadFile('data.json'))
.mapIn(parseJson())
.emit((out, $) => out
.add('name', $.get('name').string())
.add('age', $.get('age').number())
)
.compile()
const schema = JsonSchema.output(plan, {
id: 'https://example.com/schema',
title: 'User',
deduplicate: true,
})