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.2.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.2-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bfg_schemautil-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 3971dba8f2e6348f8242f5008508df7993adaf44935c1d30c32af7f917e43dcc
MD5 0e0fd8d5bfbb231884e38dbe5c342b92
BLAKE2b-256 f9c8d38e89588a818c691774aadefdfde33b4a63c3500fc720a5204e5e642888

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bfg_schemautil-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95d2190bd649737b5900f726766159ed8952c4cc06d5ce5346fd8a15f32234c2
MD5 896d0b52f7327b83f9b8e02b9625354f
BLAKE2b-256 5e53d7e4625c6fe13c0cadf3aab090c8adb0016e40f5d7685c766360ec075308

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