register_json_coercion: Register a JSON coercion handler

View source: R/schema.R

register_json_coercionR Documentation

Register a JSON coercion handler

Description

Registers a ⁠(predicate, handler)⁠ pair used by safe_to_json(): when predicate(x) is TRUE, x is replaced by handler(x) before serialization. Intended for companion packages (e.g. aisdk.datatools) to teach the core serializer about extra object types from their .onLoad hook, e.g. ggplot objects.

Usage

register_json_coercion(predicate, handler, id = NULL)

Arguments

predicate

A function taking an object and returning a single logical.

handler

A function taking an object and returning a serializable value.

id

Optional unique id; re-registering the same id replaces the handler.

Value

Invisibly TRUE.


aisdk documentation built on May 29, 2026, 9:07 a.m.