Schema
Runs in your browser· your schema or sample is converted in this tab and never uploaded
Convert Spark schemas between DDL, PySpark, Scala and JSON
Write a Spark schema once and get it in every form you need: a DDL string for spark.read.schema(...), a PySpark StructType, a Scala StructType, or the JSON that schema.json() prints. Start from a DDL string, a CREATE TABLE statement or a JSON sample. Nested arrays, maps and structs, decimals and NOT NULL are handled, and a tree shows what was read. Everything runs in your browser.
Frequently Asked Questions
- How do I convert a Spark DDL string to a PySpark StructType?
- Paste the DDL (for example "id BIGINT NOT NULL, tags ARRAY<STRING>, price DECIMAL(10,2)") and choose PySpark. The page writes the from pyspark.sql.types import line and a StructType with one StructField per column, with nullability and nested ArrayType, MapType and StructType filled in. Copy it or download schema.py.
- Can I get a schema from a JSON sample?
- Yes. Paste a JSON object, an array of objects or JSON Lines. Types are inferred the way Spark infers them from JSON: whole numbers become LONG, other numbers DOUBLE, text (dates included) STRING, and rows are merged so a column present in only some rows is kept. Every column is nullable. Check the result before you use it for production data: a sample cannot know that a string column is really a date.
- Which types are supported?
- STRING, INT, BIGINT, SMALLINT, TINYINT, FLOAT, DOUBLE, BOOLEAN, DATE, TIMESTAMP, TIMESTAMP_NTZ, BINARY and DECIMAL(p,s), plus ARRAY<...>, MAP<...> and STRUCT<...> nested to any depth, with NOT NULL and COMMENT. VARCHAR(n) and CHAR(n) are read as STRING. Interval and user-defined types are not supported.
- Is my schema uploaded anywhere?
- No. The conversion runs in your browser tab and nothing is sent to a server or stored.
Related Tools
Found this useful? Hexabench is free and ad-free. If it saved you time, you can support it.
Buy me a coffee →