Skip to content

Lua API Data

Leonard Ramminger edited this page Aug 10, 2026 · 1 revision

Lua API — Data (beez.data)

Parse, emit, merge, and validate structured data in build.lua.


Formats

type option File extensions
json .json
yaml / yml .yaml, .yml
xml .xml
csv .csv
toml .toml

Functions

Serialization

Function Input Output
deserialize_string(content, [options]) string Lua table
serialize_string(data, [options]) Lua table string
deserialize_file(path, [options]) path Lua table
serialize_file(path, data, [options]) path + table writes file

options is { type = "json" } etc. File helpers infer format from the extension when options is omitted.

Table tools

Function Description
merge(target, source) Deep-merge source into target
clone(table) Deep copy
get(table, path, [default]) Dot path lookup ("a.b.c")
set(table, path, value) Dot path assignment
diff(left, right) Field-level { from, to } changes

validate(data, schema)

Input: Lua table + schema (table or JSON string).

Output: true on success; throws on failure.

Schema keywords

Keyword Use
type null, boolean, string, integer, number, array, object
enum Allowed values (array)
required Required property names on objects
properties Per-field nested schemas
additionalProperties false to forbid extra keys
items Schema for each array element

Example

beez.data.validate(
    { name = "beez", tags = { "ci", "lua" } },
    {
        type = "object",
        required = { "name" },
        properties = {
            name = { type = "string" },
            tags = {
                type = "array",
                items = { type = "string" },
            },
        },
        additionalProperties = false,
    }
)

Examples

-- JSON round-trip
local cfg = beez.data.deserialize_file("config.json")
cfg.build.jobs = beez.sys.cpu_threads()
beez.data.serialize_file("config.generated.json", cfg)

-- TOML
local doc = beez.data.deserialize_string([[
title = "demo"
[owner]
name = "Ada"
]], { type = "toml" })

← Lua API Overview

Clone this wiki locally