TOML

Parsing

Serde.SerdeToml.parse_tomlFunction
parse_toml(x::Union{AbstractString, Vector{UInt8}}; kw...) -> Dict{String, Any}

Parse a TOML string or byte vector into a Dict{String,Any} without mapping to a target type.

Delegates to the standard library TOML.parse.

Arguments

  • x: TOML text as a String or Vector{UInt8}.

Returns

A Dict{String, Any} representing the top-level TOML document.

Throws

Examples

julia> parse_toml("host = \"localhost\"\nport = 8080")
Dict{String, Any}("host" => "localhost", "port" => 8080)

See also: from_toml, try_from_toml.

source

Deserialization

Serde.SerdeToml.from_tomlFunction
from_toml(::Type{T}, x; kw...) -> T
from_toml(strategy, ::Type{T}, x; kw...) -> T
from_toml(f::Function, x; kw...) -> Any

Parse a TOML string and deserialize it into type T.

Arguments

  • ::Type{T}: target type to construct.
  • x: TOML text as a String or Vector{UInt8}.
  • strategy: optional context object (e.g. CamelCase()).
  • f::Function: function (parsed_data) -> Type for dynamic type dispatch.

Returns

A value of type T.

Throws

Examples

julia> struct Server; host::String; port::Int; end

julia> from_toml(Server, "host = \"localhost\"\nport = 9000")
Server("localhost", 9000)

See also: try_from_toml, to_toml, parse_toml.

source

Serialization

Serde.SerdeToml.to_tomlFunction
to_toml(data; kw...) -> String
to_toml(strategy, data; kw...) -> String

Serialize data into a TOML string.

Struct fields, dicts, and arrays are mapped to TOML sections, tables, and arrays of tables following TOML conventions. Scalar fields are written as inline key-value pairs; nested structs produce [section] headers.

Pass a context object strategy (e.g. CamelCase()) as the first argument to apply global field-renaming.

All serialization traits (Serde.ser_name, Serde.ser_value, Serde.ser_skip) are applied. Null values (nothing, missing) are omitted.

Arguments

  • data: value to serialize (struct or dict).
  • strategy: optional context object.

Returns

A TOML-formatted String.

Examples

julia> struct Server; host::String; port::Int; end

julia> to_toml(Server("localhost", 8080)) |> print
host = "localhost"
port = 8080

See also: from_toml.

source