#encoding/json
Xu 0.16.0 API
import: #encoding/json
counts: 9 functions, 28 methods, 1 types, 0 constants, 0 method sets
Strict JSON and pooled Docs; as_int/as_f64 propagate conversion errors, while legacy numeric accessors retain zero fallback.
struct Doc
pub struct Doc {
pub kinds []int
pub texts []string
pub keys []string
pub firsts []int
pub nexts []int
pub lasts []int
pub root_idx int
pub err string
pub line int
pub raw string
pub i int
}
Purpose
Structure encapsulating kinds, texts, keys, firsts, nexts.
Public fields
kinds []int- field ([]int)
texts []string- field ([]string)
keys []string- field ([]string)
firsts []int- field ([]int)
nexts []int- field ([]int)
lasts []int- field ([]int)
root_idx int- field (int)
err string- error
line int- field (int)
raw string- Parse state (kept here: arrays cannot move between structs).
i int- index or integer
(Doc) ok
Purpose
Execute ok on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
Returns
bool — true or false
(Doc) error
pub fn (d Doc) error() string
Purpose
Execute error on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
Returns
string — result string
(Doc) error_line
pub fn (d Doc) error_line() int
Purpose
Operation on Doc: error line.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
Returns
int — a value of this type
(Doc) root
pub fn (d Doc) root() int
Purpose
Execute root on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
Returns
int — a value of this type
(Doc) valid_node
pub fn (d Doc) valid_node(n int) bool
Purpose
Operation on Doc: valid node.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) kind
pub fn (d Doc) kind(n int) int
Purpose
Execute kind on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
int — a value of this type
(Doc) is_dict
pub fn (d Doc) is_dict(n int) bool
Purpose
Operation on Doc: whether it is dict.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) is_list
pub fn (d Doc) is_list(n int) bool
Purpose
Operation on Doc: whether it is list.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) is_string
pub fn (d Doc) is_string(n int) bool
Purpose
Operation on Doc: whether it is string.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) is_number
pub fn (d Doc) is_number(n int) bool
Purpose
Operation on Doc: whether it is number.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) is_bool
pub fn (d Doc) is_bool(n int) bool
Purpose
Operation on Doc: whether it is bool.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) as_bool
pub fn (d Doc) as_bool(n int) bool
Purpose
Operation on Doc: as bool. Throws on failure; handle the error or propagate it to the caller.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) as_string
pub fn (d Doc) as_string(n int) string
Purpose
Operation on Doc: as string. Throws on failure; handle the error or propagate it to the caller.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
string — result string
(Doc) as_null
pub fn (d Doc) as_null(n int) int
Purpose
Operation on Doc: as null. Throws on failure; handle the error or propagate it to the caller.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
int — a value of this type
(Doc) as_int
pub fn (d Doc) as_int(n int) int
Purpose
Operation on Doc: as int. Throws on failure; handle the error or propagate it to the caller.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
int — a value of this type
(Doc) as_f64
pub fn (d Doc) as_f64(n int) f64
Purpose
Operation on Doc: as f64. Throws on failure; handle the error or propagate it to the caller.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
f64 — a value of this type
(Doc) is_null
pub fn (d Doc) is_null(n int) bool
Purpose
Operation on Doc: whether it is null.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
bool — true or false
(Doc) text
pub fn (d Doc) text(n int) string
Purpose
Operation on Doc: return the current text.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
string — result string
(Doc) key
pub fn (d Doc) key(n int) string
Purpose
Execute key on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
string — result string
(Doc) count
pub fn (d Doc) count(n int) int
Purpose
Operation on Doc: count non-overlapping occurrences.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
int — a value of this type
(Doc) at
pub fn (d Doc) at(n int, i int) int
Purpose
Execute at on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
i int- index or integer (int)
Returns
int — a value of this type
(Doc) has
pub fn (d Doc) has(n int, key string) bool
Purpose
Execute has on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
key string- key (string)
Returns
bool — true or false
(Doc) dict_keys
pub fn (d Doc) dict_keys(n int) []string
Purpose
Operation on Doc: dict keys.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
[]string — slice result
(Doc) get
pub fn (d Doc) get(n int, key string) int
Purpose
Execute get on Doc.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
key string- key (string)
Returns
int — a value of this type
(Doc) number_int
pub fn (d Doc) number_int(n int) int
Purpose
number_int is the legacy conversion: it returns 0 on conversion failure. Use as_int for type checking and a reported conversion error.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
int — a value of this type
(Doc) number_f64
pub fn (d Doc) number_f64(n int) f64
Purpose
number_f64 is the legacy conversion: it returns 0.0 on conversion failure. Use as_f64 for type checking and a reported conversion error.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
f64 — a value of this type
parse
pub fn parse(src &string) Doc
Purpose
Parse the input.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
Doc — a value of this type
parse_max
pub fn parse_max(src &string, max_bytes int) Doc
Purpose
Parse as max.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
max_bytes int- max_bytes (int)
Returns
Doc — a value of this type
escape
pub fn escape(s &string) string
Purpose
escape: JSON string body escaping (no surrounding quotes).
Parameters
s &string- source string (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
quote
pub fn quote(s &string) string
Purpose
quote: JSON string literal, surrounding quotes included.
Parameters
s &string- source string (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
unquote
pub fn unquote(s &string) string
Purpose
unquote parses exactly one JSON string literal (quotes included). Throws on failure; handle the error or propagate it to the caller.
Parameters
s &string- source string (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
(Doc) to_json
pub fn (d Doc) to_json() string
Purpose
to_json: canonical re-emission of the document (keys in parse order, strings re-escaped, numbers verbatim).
Parameters
d Doc- The
Doc instance used by this call (value receiver).
Returns
string — result string
valid
pub fn valid(src &string) bool
Purpose
Whether the value is valid.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
bool — true or false
compact
pub fn compact(src &string) string
Purpose
Execute compact. Throws on failure; handle the error or propagate it to the caller.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
indent
pub fn indent(src &string, prefix &string, gap &string) string
Purpose
Execute indent. Throws on failure; handle the error or propagate it to the caller.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
prefix &string- prefix (read-only borrow; caller keeps the original; type &string)
gap &string- gap (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
html_escape
pub fn html_escape(src &string) string
Purpose
Html escape.
Parameters
src &string- source (read-only borrow; caller keeps the original; type &string)
Returns
string — result string
(Doc) encode
pub fn (d Doc) encode(n int) string
Purpose
Re-emit one parsed subtree with the same escaping and number spelling as to_json, so consumers can retain complete nested response values. Throws on failure; handle the error or propagate it to the caller.
Parameters
d Doc- The
Doc instance used by this call (value receiver).
n int- count, length, or limit (int)
Returns
string — result string