Skip to main content

A set of utilities to generate JSON Schema from simple JSON objects

Project description

schemautil

A set of utilities to generate JSON Schema from simple JSON objects.

Example

Basic Object Schema

Given the following object schema:

{
  "type": "object",
  "properties": {
    "a": { "type": "string" },
    "b": { "type": "string" }
  },
  "required": ["a", "b"],
  "additionalProperties": false
}

You can generate this schema using:

object_schema({"a": "string", "b": "string"})

Enum Example

For an enum field:

object_schema({"status": ["enum", "pending", "approved", "rejected"]})

Generates:

{
  "type": "object",
  "properties": {
    "status": {
      "type": "string",
      "enum": ["pending", "approved", "rejected"]
    }
  },
  "required": ["status"],
  "additionalProperties": false
}

Rules

  • All fields are required and additionalProperties is always set to false.

  • To make a field nullable, add a ? to the end of its name. Example: {"a": "string", "b?": "string"} (b is nullable)

  • To define an array, wrap the type in brackets. Example: {"a": "string", "b": ["string"]} (b is an array of strings) Note: There should be only one type in the array.

  • To define a field that can be one of multiple types, list the types in brackets. Example: {"a": "string", "b": ["string", "number"]} (b can be a string or a number)

  • To define an enum (restricted set of string values), use ["enum", ...values]. Example: {"status": ["enum", "pending", "approved", "rejected"]} (status must be one of these specific strings)

    Note: The library distinguishes between type unions and enums:

    • ["string", "number"] → Type union (can be any string or any number)
    • ["enum", "pending", "approved"] → String enum (must be exactly one of these values)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bfg_schemautil-0.1.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bfg_schemautil-0.1.3-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file bfg_schemautil-0.1.3.tar.gz.

File metadata

  • Download URL: bfg_schemautil-0.1.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.9

File hashes

Hashes for bfg_schemautil-0.1.3.tar.gz
Algorithm Hash digest
SHA256 42d126e43fd9204fc435356b71ff7ab7f5051008fadc4e23f169cb4142a62782
MD5 2b5cbef0b1b7a54ae1b07e6a679e9237
BLAKE2b-256 44ca7d64151a10e3e180685eb31e74ddcf6f9c3a27e4c8e02691867d9130d162

See more details on using hashes here.

File details

Details for the file bfg_schemautil-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bfg_schemautil-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 01a746acfdffbb48b454fe2b83f4c16ada3f5577ca2d2e713e6caff212c21b1e
MD5 76b609b42ab42a3e17d90a3dc0b92787
BLAKE2b-256 28aba0a8617554b21acde0f15827e646c074d384c86e46e21e80f882b382da66

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page