Json module

from_json

procedure · 2 overloadsSource

Decodes a T from a source in pieces. The pieces are gathered in one buffer (the decoder wants the whole document, and its strings are copied out of it, so the buffer is freed before this returns) and then decoded exactly as from_json(T, text) would, so a document split at any byte gives the same value or the same error. A source that fails gives a .READ error with the source's text; a document longer than options.max_size is a .LIMIT error and the rest is not read.

from_json :: (
    $T: Type,
    source: Json_Source,
    options := Json_Options.{}
) -> (T, Json_Error)

Decodes a T from a source in pieces. The pieces are gathered in one buffer (the decoder wants the whole document, and its strings are copied out of it, so the buffer is freed before this returns) and then decoded exactly as from_json(T, text) would, so a document split at any byte gives the same value or the same error. A source that fails gives a .READ error with the source's text; a document longer than options.max_size is a .LIMIT error and the rest is not read.

Parameters

$T: Type
source: Json_Source
options := Json_Options.{}

Returns

T
from_json :: (
    $T: Type,
    text: string,
    options := Json_Options.{}
) -> (T, Json_Error)

Decodes text into a T. Strings, arrays, pointers and tables in the result are allocated from context.allocator; free_json releases them. After a failure everything the decoder allocated has been freed already and the returned value is a default T.

Parameters

$T: Type
text: string
options := Json_Options.{}
nesting and size limits, and whether unknown fields are an error.

Returns

T

See also