def json.go

yaml-for-bend@0.1.1.0 · value.bend:303

import yaml-for-bend@0.1.1.0/value.bend as Value
import Base

303def json.go(v: Yaml, +first: Bool) -> String:
304  match v:
305    case Null{}:
306      "null"
307    case Boolean{on}:
308      Bool.pick(String, on, "true", "false")
309    case Int{t}:
310      t
311    case Float{t}:
312      json.float(t)
313    case Str{t}:
314      json.str(t)
315    case Seq{xs}:
316      match xs:
317        case Nil{}:
318          Bool.pick(String, first, "[]", "]")
319        case Con{x, rest}:
320          Bool.pick(String, first, "[", ",") ++ json.go(x, True{}) ++ json.go(Seq{rest}, False{})
321    case Mapping{es}:
322      match es:
323        case Nil{}:
324          Bool.pick(String, first, "{}", "}")
325        case Con{Entry{+k, x}, rest}:
326          Bool.pick(String, first, "{", ",") ++ key.json(is_str(k), json.go(k, True{})) ++ ":" ++ json.go(x, True{}) ++ json.go(Mapping{rest}, False{})
327    case Tagged{tag, x}:
328      json.go(x, True{})

Uses (11)

Used by (1)