main.bend checks
raw source on the hub · import emerging-ezjson@1.1.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.
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 15 · raw
@txt:String -> Maybe<&2, 0x81c67699424929b5c44cd8577e18117f/src/value.Json>
a text as a value, or None when it is not JSON
def print source · line 19 · raw
@val:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> String
a value as compact JSON
def pretty source · line 24 · raw
@val:0x81c67699424929b5c44cd8577e18117f/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 28 · raw
0x81c67699424929b5c44cd8577e18117f/src/value.Json
null
def bool source · line 32 · raw
@flag:Bool -> 0x81c67699424929b5c44cd8577e18117f/src/value.Json
a boolean
def str source · line 36 · raw
@txt:String -> 0x81c67699424929b5c44cd8577e18117f/src/value.Json
a string
def num source · line 40 · raw
@raw:String -> 0x81c67699424929b5c44cd8577e18117f/src/value.Json
a JSON number from its text, or null when that text is not one
def obj source · line 44 · raw
@pairs:List<&1, Pair(String, 0x81c67699424929b5c44cd8577e18117f/src/value.Json)> -> 0x81c67699424929b5c44cd8577e18117f/src/value.Json
an object from pairs
def arr source · line 48 · raw
@items:List<&2, 0x81c67699424929b5c44cd8577e18117f/src/value.Json> -> 0x81c67699424929b5c44cd8577e18117f/src/value.Json
an array from a list
def get source · line 53 · raw
@val:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> @key:String -> 0x81c67699424929b5c44cd8577e18117f/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 57 · raw
@val:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> @idx:U32 -> 0x81c67699424929b5c44cd8577e18117f/src/value.Json
an array's item at an index; JNull when it is not an array or has none
def has source · line 62 · raw
@val:0x81c67699424929b5c44cd8577e18117f/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 66 · raw
@val:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> U32
how many elements an array, or members an object, has; 0 for anything else
def as_bool source · line 70 · raw
@val:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> Maybe<&2, Bool>
a boolean, or none when the value is not one
def as_str source · line 74 · raw
@val:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> Maybe<&2, String>
a string, or none when the value is not one
def as_num source · line 78 · raw
@val:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> Maybe<&2, String>
a number's text, or none when the value is not a number
def as_u32 source · line 82 · raw
@val:0x81c67699424929b5c44cd8577e18117f/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 86 · raw
@val:0x81c67699424929b5c44cd8577e18117f/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 92 · raw
@src:String -> 0x81c67699424929b5c44cd8577e18117f/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 97 · raw
@cur:0x81c67699424929b5c44cd8577e18117f/src/pull.Cur -> Pair(0x81c67699424929b5c44cd8577e18117f/src/pull.Ev, 0x81c67699424929b5c44cd8577e18117f/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 101 · raw
@cur:0x81c67699424929b5c44cd8577e18117f/src/pull.Cur -> 0x81c67699424929b5c44cd8577e18117f/src/pull.Cur
drop the next value, scalar or container, without building it
def text source · line 105 · raw
@ev:0x81c67699424929b5c44cd8577e18117f/src/pull.Ev -> Maybe<&2, String>
the text of a string, key, or number event, copying a span. None otherwise