CToon
v0.9.0 GitHub

Usage

Encoding and decoding

matlab
% Encode a MATLAB struct to a TOON string
s = ctoon.encode(struct('name', 'Alice', 'age', uint64(30), 'active', true));

% Decode back
v = ctoon.decode(s);
v.name    % → 'Alice'
v.age     % → uint64(30)
v.active  % → true

File I/O

matlab
% Write
cfg.host = 'localhost';
cfg.port = uint64(8080);
ctoon.write(cfg, 'config.toon');

% Read
cfg = ctoon.read('config.toon');

Type mapping

MATLAB type

TOON type

[] (empty double)

null

logical scalar

bool

double scalar

real

int64 scalar

signed integer

uint64 scalar

unsigned integer

char / string

str

cell array

array

struct (scalar)

object

TOON spec version

The toon-format/spec release this build targets is returned in the metadata struct of ctoon.version:

matlab
[~, info] = ctoon.version();
info.Spec.Version   % → '4.1'
info.Spec.Tag       % → 'v4.1.2'
info.Spec.Date      % → '2026-07-26'

ctoon.version() with no output also prints it.

Error handling

All functions throw MATLAB errors with structured identifiers:

matlab
try
    v = ctoon.decode('bad input');
catch e
    e.identifier   % → 'ctoon:decodeError'
    e.message
end

Identifier

Cause

ctoon:decodeError

Invalid TOON string

ctoon:readError

File not found or parse error

ctoon:writeError

Cannot write to file

ctoon:badArg

Wrong argument type