OxL Reference

method Decoder.isJson

Whether the input is JSON.

Example:

oxl✓ checked in CI
use std.ser { Codec, Encoder, Decoder, Schema, encode, decode, hex, EncodeError, DecodeError }

data Flexible {}

impl Codec<i64> for Flexible {
  static fn encode(x: &i64, w: &var Encoder) -> () | EncodeError { w.writeI64(x) }
  static fn decode(r: &var Decoder) -> i64 | DecodeError {
    if r.isJson() {
      match r.readStr() {
        str s => match s.parse<i64>() {
          i64 n => n
          ParseError _ => fail DecodeError.Invalid(msg: "not a number")
        }
        DecodeError e => fail e
      }
    } else {
      r.readI64()
    }
  }
  static fn schema() -> Schema => Schema.of("int64")
}
fn isJson() -> bool

Since. 1.0.0-beta

Returns

bool

Effects

none declared (pure unless the body says otherwise)

Defined in: std/ser/ser.oxl:1490

See also