Databricks PySpark
Translates JSON Schema to Databricks PySpark StructType definitions with metadata (.py).
Example
Input (JSON Schema):
{
"type": "object",
"properties": {
"name": { "type": "string", "description": "Full name" },
"age": { "type": "integer", "minimum": 0, "maximum": 150 },
"status": { "type": "integer", "minimum": -128, "maximum": 127 },
"price": { "type": "number", "multipleOf": 0.01, "minimum": 0, "maximum": 99999.99 }
}
}
Output (Databricks PySpark):
import pyspark.sql.types as T
orders_schema = T.StructType([
T.StructField("name", T.StringType(), nullable=True, metadata={"comment": "Full name"}),
T.StructField("age", T.ShortType(), nullable=True),
T.StructField("status", T.ByteType(), nullable=True),
T.StructField("price", T.DecimalType(7, 2), nullable=True),
])
When minimum and maximum are specified, integers are narrowed to the smallest fitting type (ByteType, ShortType, IntegerType, or LongType). When multipleOf is a decimal fraction (e.g. 0.01), numbers become DecimalType with precision derived from the bounds and scale from multipleOf. Descriptions are emitted as metadata={"comment": ...}.
Supported JSON Schema Features
Type Keywords
Type Values
- string
- integer
- number
- boolean
- array
- object
- null
Schema Composition
Object Keywords
- properties
- required
- additionalProperties
- patternProperties
- propertyNames
- minProperties / maxProperties
- unevaluatedProperties
- dependentRequired
Array Keywords
- items
- prefixItems
- contains
- minItems / maxItems
- uniqueItems
- unevaluatedItems
- maxContains / minContains
Numeric Validation
- minimum / maximum
- exclusiveMinimum / exclusiveMaximum
- multipleOf
String Validation
- minLength / maxLength
- pattern
References & Definitions
- $ref
- $defs
- $id
- $anchor
- $dynamicRef / $dynamicAnchor
- date
- date-time
- time
- duration
- uuid
- uri / uri-reference / uri-template
- iri / iri-reference
- email / idn-email
- hostname / idn-hostname
- ipv4 / ipv6
- json-pointer / relative-json-pointer
- regex
Annotations
- description
- title
- default
- deprecated
- readOnly / writeOnly
- examples
Conditional
- if / then / else
- dependentSchemas
Content
- contentEncoding
- contentMediaType
- contentSchema