parseFromTokenSourceLeaky
scanner_or_reader must be either a *std.json.Scanner with complete input or a *std.json.Reader.
Allocations made during this operation are not carefully tracked and may not be possible to individually clean up.
It is recommended to use a std.heap.ArenaAllocator or similar.
Function parameters
Parameters
- T:type
- scanner_or_reader:anytype
Controls how to deal with various inconsistencies between the JSON document and the Zig struct type passed in.
Types
- ParseOptions
- Controls how to deal with various inconsistencies between the JSON document and the Zig struct type passed in.
Functions in this namespace
Functions
- parseFromSlice
- Parses the json document from `s` and returns the result packaged in a `std.json.Parsed`.
- parseFromSliceLeaky
- Parses the json document from `s` and returns the result.
- parseFromTokenSource
- `scanner_or_reader` must be either a `*std.json.Scanner` with complete input or a `*std.json.Reader`.
- parseFromTokenSourceLeaky
- `scanner_or_reader` must be either a `*std.json.Scanner` with complete input or a `*std.json.Reader`.
- parseFromValue
- Like `parseFromSlice`, but the input is an already-parsed `std.json.Value` object.
- ParseError
- The error set that will be returned when parsing from `*Source`.
- innerParse
- This is an internal function called recursively
- innerParseFromValue
- This is an internal function called recursively
Error sets in this namespace
Error Sets
Source
Implementation
pub fn parseFromTokenSourceLeaky(
comptime T: type,
allocator: Allocator,
scanner_or_reader: anytype,
options: ParseOptions,
) ParseError(@TypeOf(scanner_or_reader.*))!T {
if (@TypeOf(scanner_or_reader.*) == Scanner) {
assert(scanner_or_reader.is_end_of_input);
}
var resolved_options = options;
if (resolved_options.max_value_len == null) {
if (@TypeOf(scanner_or_reader.*) == Scanner) {
resolved_options.max_value_len = scanner_or_reader.input.len;
} else {
resolved_options.max_value_len = default_max_value_len;
}
}
if (resolved_options.allocate == null) {
if (@TypeOf(scanner_or_reader.*) == Scanner) {
resolved_options.allocate = .alloc_if_needed;
} else {
resolved_options.allocate = .alloc_always;
}
}
const value = try innerParse(T, allocator, scanner_or_reader, resolved_options);
assert(.end_of_document == try scanner_or_reader.next());
return value;
}