Http module

json

procedureextensionexperimentalSource

value as JSON with Content-Type: application/json. The body is built in the temporary allocator.

Example
response := json(s32.[1, 2, 3]);
assert(response.status == 200);
assert(string.{ response.body.count, response.body.data } == "[1,2,3]");

Doesn't run in the browser (skipped on wasm).

json :: (value: $T, status := 200) -> Response

value as JSON with Content-Type: application/json. The body is built in the temporary allocator.

Parameters

value: $T
any value the Json module can encode.
status := 200
the HTTP status code.

Returns

Example
response := json(s32.[1, 2, 3]);
assert(response.status == 200);
assert(string.{ response.body.count, response.body.data } == "[1,2,3]");

Doesn't run in the browser (skipped on wasm).

See also