LEARN VOID
Reading JSON data
Decode a numeric document into a checked source type before using its value.
use json
func entry(additional: i32) -> i32:
if json.parse_as<i32>("3") is Ok(var shelves):
return shelves + additional
return 0Input 2Expected result 5
Read a typed value
json.parse_as<i32> checks the input against the requested type. Here the document contains a shelf count. Three shelves plus the two supplied by the caller give five.
Set a parsing budget
JSON operations accept a json.limits value. Treat malformed syntax, incompatible fields and exhausted budgets as recoverable errors. Typed decoding rejects unknown fields by default.
Write JSON text
json.stringify(value) returns a result. Check it before passing the text to a file or HTTP request. Use the dynamic json.value API when the document shape is not known in advance.
Continue learning with Text encodings · HTTP clients.