OxL Reference

method Encoder.isJson

Whether the format is JSON (codecs may then write a different representation: @codec(json: C)).

Example:

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

data Both {}

impl Codec<i64> for Both {
  static fn encode(x: &i64, w: &var Encoder) -> () | EncodeError {
    if w.isJson() { w.writeStr("n{x}") } else { w.writeI64(x) }
  }
  static fn decode(r: &var Decoder) -> i64 | DecodeError { r.readI64() }
  static fn schema() -> Schema => Schema.of("int64")
}

fn main() io {
  print("ok")
}
Output
ok
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:450

See also