[whatwg/webidl] Parameter types that must be JSON serializable (Issue #1537)

reillyeon created an issue (whatwg/webidl#1537)

### What is the issue with the Web IDL Standard?

The WebML CG is considering interfaces for "function calling" in ML models, where the input or output of an LLM is a request to execute code with some given parameters and the result provided back to the LLM. For sake of argument, assume that the model consumes and produces JSON, though it may use a similar format which is 1:1 convertible to JSON.

We would like to define the API for passing an object to the model as a function which accepts any Javascript value which is serializable to JSON, however there does not appear to be any corresponding WebIDL type.

The closest option is `any`, which represents many non-serializable types. There is a definition of [JSON types](https://webidl.spec.whatwg.org/#dfn-json-types) which leads me to consider a method which accepts a parameter of type `any` but throws a `TypeError` if the parameter is "not a JSON type" but there isn't any specified algorithm for that check.

The only similar example I can find in another specification is the [fetch an identity assertion](https://w3c-fedid.github.io/FedCM/#fetch-identity-assertion) algorithm out of the Federated Credential Management API however in that case the algorithm simply serializes the value to JSON which makes sense in that context because the serialized value is going to be transmitted in an HTTP request.

In our case the goal is less to specify a particular serialization format and more to specify that the value must be serializable to some kind of textual representation in general. Maybe this is splitting hairs and using [serialize a JavaScript value to a JSON string](https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-a-json-string) as FedCM does is good enough even if implementations may not ever represent the value as a literal JSON string.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/1537
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/1537@github.com>

Received on Thursday, 6 November 2025 01:05:53 UTC