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.4.tar.gz (6.2 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.4-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bfg_schemautil-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3aa117edde0557aee167e9529232f55e524d87e9f8b7b5c6f531b8a51ff4a321
MD5 428d720c215a7b0912e1f317c9702f5c
BLAKE2b-256 ab3d408a39717bba5cacf414795728db5975b3c22c41e8b65187724b3f6074d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bfg_schemautil-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f4f03fb069916551b6af734ab636bbe449e012825b87f372fe55764120e1549a
MD5 cff43f0af0e91af78b6b073e3a2202ec
BLAKE2b-256 cd30bb9a5d15d0a0f7cdc77e9a693a6edb67b0007b309817108154b2829b2297

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