• Recursively convert an arbitrary value into a JSON-safe representation that defaultFromJSON can faithfully revive.

    Parameters

    • value: any

      The value to serialize.

    Returns JsonValue | undefined

    A JSON-safe value, or undefined if the value is non-serializable.

    Scalars pass through; bigint, Date, URL, SohlMap, Map, Set, RegExp, and Error are encoded with tagged forms. Foundry documents (those with a documentName) are reduced to a ClientDocument reference by UUID. Functions, symbols, and undefined are dropped (return undefined) — no executable source and no function reference is ever emitted. Objects with a toJSON method delegate to it, with nested undefined canonicalized to null (see nullifyUndefined); other objects are serialized key by key (omitting keys whose values serialize to undefined).