std:json リファレンス
import json := "std:json" で取得する JSON 直列化モジュール。JSON テキストと Hikari 値の相互変換 (decode / parse / stringify) を提供する。
decode
decode(text, type T) decode: { String, type a | Result(a) }
JSON テキストを型 T の値として復号する (同期)。型が合わなければ Err。
スキーマが分かっているなら parse ではなくこちらを使う (結果型が Result(T) に確定する)。
parse
parse(text)
parse: { String | Result(Value) }
JSON テキストを再帰的な json.Value へ復号し Result(Value) を返す (同期)。object のキー順を保持する。
>>> json.parse "[1,2]" Ok(Array([Int(1), Int(2)]))
stringify
stringify(value, indent)
stringify: { Any, Int | Result(String) }
Hikari 値を JSON テキストへ符号化する (indent = 0 でコンパクト。省略できない)。
>>> json.stringify([1, 2], 0) Ok("[1,2]")