Function

judo_scan

Incrementally scan JSON.

Since v1.0
enum judo_result judo_scan(
struct judo_stream *stream, const char *source, int32_t length)

Parameters πŸ”—

stream inout

Scanner state.

source in

JSON source text.

length in

Number of code units in source or a negative integer if it’s null-terminated.

Return Value πŸ”—

JUDO_RESULT_SUCCESS

If source was scanned successfully.

JUDO_RESULT_BAD_SYNTAX

If source is malformed JSON.

JUDO_RESULT_ILLEGAL_BYTE_SEQUENCE

If source has a malformed UTF-8 encoded character.

JUDO_RESULT_INVALID_OPERATION

If stream or source are NULL.

JUDO_RESULT_MAXIMUM_NESTING

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

JUDO_RESULT_MALFUNCTION

If there is a defect in the implementation.

Discussion πŸ”—

The judo_scan function reads source as JSON and populates stream with the current token. The number of code units in source is specified by length, which, if negative, indicates that source is null-terminated.

The caller must zero-initialize stream before the first call to this function. The implementation will update stream as source is scanned. The caller must never modify stream otherwise the behavior is undefined.

The caller may copy stream with memcpy to preserve its state.