~/bend-docscommunity

main.bend source

main.bend on the hub · documented module

# ezjson: JSON for Bend 2. `parse` turns text into Maybe Json; `print` writes# compact text. Build with `obj`, `arr`, and `num`; read with `get`,# `str_or`, and `u32_or`. Constructors of Json live in ./value.bend.import Baseimport ./value.bend as Valueimport ./parse.bend as Parseimport ./print.bend as Print# a text as a value, or None when it is not JSONdef parse(s: String) -> Maybe<&2, Value.Json>:  Parse.parse(s)# a value as compact JSONdef print(j: Value.Json) -> String:  Print.print(j)# an object from pairsdef obj(pairs: List<&1, String & Value.Json>) -> Value.Json:  Value.obj(pairs)# an array from a listdef arr(items: List<&2, Value.Json>) -> Value.Json:  Value.arr(items)# a numberdef num(n: U32) -> Value.Json:  Value.num(n)# an object's value at a key; JNull when it is not an object or has no such# keydef get(j: Value.Json, key: String) -> Value.Json:  Value.get(j, key)# a string's text, else the defaultdef str_or(j: Value.Json, default: String) -> String:  Value.str_or(j, default)# a number as a U32, else the defaultdef u32_or(j: Value.Json, default: U32) -> U32:  Value.u32_or(j, default)