jsonschema

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 4 Imported by: 0

Documentation

Overview

Package jsonschema provides JSON Schema inference from arbitrary JSON data. It generates schemas following JSON Schema Draft 2020-12.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferFromValue

func InferFromValue(v any) *jsonschema.Schema

InferFromValue generates a JSON Schema from an already-parsed JSON value.

Types

type InferOptions

type InferOptions struct {
	// StrictRequired marks properties as required only if present in ALL samples.
	// When true with multiple samples: only fields in ALL samples are required.
	// When true with single sample: ALL present fields are required.
	// When false: no fields are marked as required.
	// Default: true
	StrictRequired bool
	// AdditionalProperties sets additionalProperties in object schemas.
	// Default: nil (not set)
	AdditionalProperties *bool
	// MarkNullableAsOptional treats fields that can be null as optional (not required).
	// Default: true
	MarkNullableAsOptional bool
}

InferOptions controls schema inference behavior.

func DefaultInferOptions

func DefaultInferOptions() *InferOptions

DefaultInferOptions returns the default inference options.

type InferredSchema

type InferredSchema struct {
	Schema      *jsonschema.Schema `json:"schema"`       // JSON Schema (Draft 2020-12)
	SampleCount int                `json:"sample_count"` // Number of samples used
	AllMatch    bool               `json:"all_match"`    // True if all samples had identical schema
}

InferredSchema contains a JSON Schema inferred from sample data along with metadata.

func Infer

func Infer(samples ...[]byte) (*InferredSchema, error)

Infer generates a JSON Schema from one or more JSON byte samples. Returns a merged schema if multiple samples are provided.

func InferWithOptions

func InferWithOptions(opts *InferOptions, samples ...[]byte) (*InferredSchema, error)

InferWithOptions generates a JSON Schema with custom options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL