json_mlake ยท API

json.streaming

Structs

StreamingParser

struct StreamingParser

Streaming JSON parser for processing large files.

Reads files in chunks and yields complete JSON values as they become available. Ideal for NDJSON files where each line is independent.

Example: var parser = StreamingParser("large_file.ndjson") while parser.has_next(): var value = parser.next() process(value) parser.close().

Implements Movable

__init__

def __init__(out self, path: String, chunk_size: Int = Int(65536))

Open a file for streaming parsing.

Args
path: Path to the JSON file.
chunk_size: Size of chunks to read (default 64KB).

close

def close(mut self)

Close the file handle.

has_next

def has_next(mut self) -> Bool

Check if there are more JSON values to read.

next

def next(mut self) -> Value

Read and parse the next JSON value.

Raises Error if no more values or parse error.

ArrayStreamingParser

struct ArrayStreamingParser

Streaming parser for JSON array files.

Parses a file containing a single JSON array and yields elements one at a time without loading the entire array.

Implements Movable

__init__

def __init__(out self, path: String, chunk_size: Int = Int(65536))

Open a JSON array file for streaming.

Args
path: Path to the JSON file.
chunk_size: Size of chunks to read.

close

def close(mut self)

Close the file handle.

has_next

def has_next(mut self) -> Bool

Check if there are more array elements.

next

def next(mut self) -> Value

Read and parse the next array element.

Functions

stream_ndjson

def stream_ndjson(path: String, chunk_size: Int = Int(65536)) -> StreamingParser

Create a streaming parser for an NDJSON file.

Example: var parser = stream_ndjson("logs.ndjson") while parser.has_next(): var entry = parser.next() if entry["level"].string_value() == "error": print(entry) parser.close().

Args
path: Path to the NDJSON file.
chunk_size: Size of chunks to read (default 64KB).

stream_json_array

def stream_json_array(path: String, chunk_size: Int = Int(65536)) -> ArrayStreamingParser

Create a streaming parser for a JSON array file.

Parses files containing a single JSON array, yielding each element one at a time.

Example: var parser = stream_json_array("users.json") # [{"name":"Alice"},...]. while parser.has_next(): var user = parser.next() print(user["name"].string_value()) parser.close().

Args
path: Path to the JSON file containing an array.
chunk_size: Size of chunks to read (default 64KB).