Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

to-json / from-json

Convert between TeaLeaf text format and JSON.

to-json

Convert a TeaLeaf text file to JSON.

Usage

tealeaf to-json <input.tl> [-o <output.json>]

Arguments

ArgumentRequiredDescription
<input.tl>YesPath to the TeaLeaf text file
-o <output.json>NoOutput file path. If omitted, writes to stdout

Examples

# Write to file
tealeaf to-json data.tl -o data.json

# Write to stdout
tealeaf to-json data.tl

# Pipe to another tool
tealeaf to-json data.tl | jq '.users'

Output Format

The output is pretty-printed JSON. See JSON Interoperability for type mapping details.


from-json

Convert a JSON file to TeaLeaf text format with automatic schema inference.

Usage

tealeaf from-json <input.json> -o <output.tl>

Arguments

ArgumentRequiredDescription
<input.json>YesPath to the JSON file
-o <output.tl>YesPath for the output TeaLeaf text file

Schema Inference

from-json automatically infers schemas from JSON arrays of uniform objects:

  1. Array Detection – identifies arrays where all elements are objects with identical keys
  2. Name Inference – singularizes the parent key name ("users"user schema)
  3. Type Inference – determines field types across all items
  4. Nullable Detection – fields with any null become nullable (string?)
  5. Nested Schemas – creates schemas for nested uniform objects

Examples

# Convert with schema inference
tealeaf from-json api_data.json -o structured.tl

# Full pipeline: JSON → TeaLeaf text → Binary
tealeaf from-json data.json -o data.tl
tealeaf compile data.tl -o data.tlbx

Example: Schema Inference in Action

Input (employees.json):

{
  "employees": [
    {"id": 1, "name": "Alice", "dept": "Engineering"},
    {"id": 2, "name": "Bob", "dept": "Design"}
  ]
}

Output (employees.tl):

@struct employee (dept: string, id: int, name: string)

employees: @table employee [
  ("Engineering", 1, "Alice"),
  ("Design", 2, "Bob"),
]

See Also