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 string or a negative integer if it’s null-terminated.

Return Value πŸ”—

JUDO_SUCCESS

If string was scanned successfully.

JUDO_BAD_SYNTAX

If string is malformed JSON.

JUDO_ILLEGAL_BYTE_SEQUENCE

If string has a malformed UTF-8 encoded character.

JUDO_INVALID_OPERATION

If stream or string are NULL.

JUDO_MAXIMUM_NESTING

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

JUDO_MALFUNCTION

If there is a defect in the implementation.

Discussion πŸ”—

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

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

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