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 *user_data, judo_memfunc memfunc)

Parameters 🔗

source in

JSON text encoded as UTF-8.

length in

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

root out

The root of the JSON tree.

error out

Error details if an error occurs.

user_data in

User pointer to pass through to memfunc.

memfunc in

Memory allocator callback.

Return Value 🔗

JUDO_SUCCESS

If string was parsed into a tree successfully.

JUDO_BAD_SYNTAX

If string is malformed JSON.

JUDO_ILLEGAL_BYTE_SEQUENCE

If string has an erroneously encoded Unicode character.

JUDO_INVALID_OPERATION

If string, root, or memfunc are NULL.

JUDO_MAXIMUM_NESTING

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

JUDO_OUT_OF_MEMORY

If dynamic memory allocation fails.

JUDO_MALFUNCTION

If there is a defect in the implementation.

Discussion 🔗

The judo_parse function parses string 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 string must be UTF-8 encoded and its length specified by length in code units. If length is negative, then string is interpreted as being null terminated.

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