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:

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

Enum Example

For an enum field:

obj_schema({"status": ["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), list the allowed string values in brackets. Example: {"status": ["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)
    • ["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.1.tar.gz (6.0 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.1-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bfg_schemautil-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c330269e33b5485229d143c577e7bf5923e4ab2d93e82035b06993ea8acc6923
MD5 edc3fea1e855ff1d0bfd83b97f416ae3
BLAKE2b-256 acfbc7a3ebb9330607c29ecd682617ee95f3e58ff4f428883f7c4a724b5ce3f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bfg_schemautil-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ed0e384f42a86a152e15749df4f5f079a4ec4c18fe0adbf91fa78d6a032a8ae
MD5 7ba11dc81df58adf99497dee8a04a730
BLAKE2b-256 de2a0cb63230639f8df0949f6005c4f67d3089650af40698096aba6608a82b15

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