main.bend checks
raw source on the hub · import emerging-ezjson@1.2.0.0/main.bend as Main
ezjson: JSON for Bend 2, with a parser, a printer and a pull cursor
parse reads text into Maybe Json. print writes compact text and
pretty indented text. cursor reads one event at a time. Build null,
booleans, numbers, strings, arrays, and objects; read them with get, at, and
as_bool, as_str, as_num, as_u32, as_f32; has and len tell a missing key or
index from a null; items lists an array's elements, and is_arr and is_obj
tell the containers apart.
5 imports
import Base import ./src/value.bend as Value import ./src/parse.bend as Parse import ./src/print.bend as Print import ./src/pull.bend as Pull
Definitions
def parse source · line 16 · raw
@txt:String -> Maybe<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>
a text as a value, or None when it is not JSON
def print source · line 20 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> String
a value as compact JSON
def pretty source · line 25 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> String
a value as JSON indented two spaces a level, one element or member a line, with no newline at the end
def null source · line 29 · raw
0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
null
def bool source · line 33 · raw
@flag:Bool -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
a boolean
def str source · line 37 · raw
@txt:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
a string
def num source · line 41 · raw
@raw:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
a JSON number from its text, or null when that text is not one
def obj source · line 45 · raw
@pairs:List<&1, Pair(String, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json)> -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
an object from pairs
def arr source · line 49 · raw
@items:List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json> -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
an array from a list
def get source · line 54 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @key:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
an object's value at a key; JNull when it is not an object or has no such key
def at source · line 58 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @idx:U32 -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
an array's item at an index; JNull when it is not an array or has none
def has source · line 63 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @key:String -> Bool
whether an object has a key; false when the value is not an object. Tells
a missing key from a key whose value is null, which get does not
def len source · line 67 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> U32
how many elements an array, or members an object, has; 0 for anything else
def items source · line 72 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>
an array's elements, in order; [] when the value is not an array. One
walk of the array, where a loop over at walks it again for every index
def is_arr source · line 76 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Bool
whether a value is an array
def is_obj source · line 80 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Bool
whether a value is an object
def as_bool source · line 84 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Maybe<&2, Bool>
a boolean, or none when the value is not one
def as_str source · line 88 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Maybe<&2, String>
a string, or none when the value is not one
def as_num source · line 92 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Maybe<&2, String>
a number's text, or none when the value is not a number
def as_u32 source · line 96 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Maybe<&2, U32>
a number as a U32, or none when it is not one or does not fit
def as_f32 source · line 100 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Maybe<&2, F32>
a number as an F32, or none when it is not one or does not fit
def cursor source · line 106 · raw
@src:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/pull.Cur
a cursor at the start of a JSON text. It holds the unread suffix of that
text. A span event keeps its own suffix, so it stays valid after next
moves the cursor, and it is gone when the event is dropped
def next source · line 111 · raw
@cur:0xa81e161008ecc2f297c0a3065cb9b188/src/pull.Cur -> Pair(0xa81e161008ecc2f297c0a3065cb9b188/src/pull.Ev, 0xa81e161008ecc2f297c0a3065cb9b188/src/pull.Cur)
the next event. Commas and colons are not events. After the root value, the next call is the end, or an error if another value follows
def skip source · line 115 · raw
@cur:0xa81e161008ecc2f297c0a3065cb9b188/src/pull.Cur -> 0xa81e161008ecc2f297c0a3065cb9b188/src/pull.Cur
drop the next value, scalar or container, without building it
def text source · line 119 · raw
@ev:0xa81e161008ecc2f297c0a3065cb9b188/src/pull.Ev -> Maybe<&2, String>
the text of a string, key, or number event, copying a span. None otherwise