Function

judo_parse

Build an in-memory tree.

Since v1.0
enum judo_result judo_parse(
const char *source, int32_t length, judo_value **root, struct judo_error *error, void *udata, judo_memfunc memfunc)

Parameters 🔗

source in

JSON text encoded as UTF-8.

length in

Number of code units in source or a negative integer if source is null terminated.

root out

The root of the JSON tree.

error out

Error details if an error occurs.

udata in

User pointer to pass through to memfunc.

memfunc in

Memory allocator callback.

Return Value 🔗

JUDO_RESULT_SUCCESS

If source was parsed into a tree successfully.

JUDO_RESULT_BAD_SYNTAX

If source is malformed JSON.

JUDO_RESULT_ILLEGAL_BYTE_SEQUENCE

If source has an erroneously encoded Unicode character.

JUDO_RESULT_INVALID_OPERATION

If source, root, or memfunc are NULL.

JUDO_RESULT_MAXIMUM_NESTING

If source defines JSON with compound structures nested deeper than JUDO_MAXDEPTH.

JUDO_RESULT_OUT_OF_MEMORY

If dynamic memory allocation fails.

JUDO_RESULT_MALFUNCTION

If there is a defect in the implementation.

Discussion 🔗

The judo_parse function parses source as JSON, constructs an in-memory tree structure from it, and assigns the root of the tree to root. If an error occurs, then error will be populated with description and location information.

The source must be UTF-8 encoded and its length specified by length in code units. If length is negative, then source is interpreted as being null terminated.

The memfunc function must implement a memory allocator as described in judo_memfunc. The udata pointer is passed to memfunc as-is.