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 optionFile extensions
json.json
yaml / yml.yaml, .yml
xml.xml
csv.csv
toml.toml

Functions

Serialization

FunctionInputOutput
deserialize_string(content, [options])stringLua table
serialize_string(data, [options])Lua tablestring
deserialize_file(path, [options])pathLua table
serialize_file(path, data, [options])path + tablewrites file

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

Table tools

FunctionDescription
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

KeywordUse
typenull, boolean, string, integer, number, array, object
enumAllowed values (array)
requiredRequired property names on objects
propertiesPer-field nested schemas
additionalPropertiesfalse to forbid extra keys
itemsSchema 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-triplocalcfg=beez.data.deserialize_file("config.json")
cfg.build.jobs=beez.sys.cpu_threads()
beez.data.serialize_file("config.generated.json", cfg)
-- TOMLlocaldoc=beez.data.deserialize_string([[title = "demo"[owner]name = "Ada"]], { type="toml" })

← Lua API Overview

Clone this wiki locally