Skip to content

Conversation

@hudlow
Copy link

@hudlow hudlow commented Oct 22, 2025

No description provided.

Comment on lines 83 to 103
function toJsonCompatibleValue(
value: CEL.CelValue,
): ReturnType<(typeof JSON)["parse"]> {
if (CEL.isCelMap(value)) {
return Object.fromEntries(
[...value.entries()].map(
([k, v]): [string, ReturnType<(typeof JSON)["parse"]>] => [
k.toString(),
toJsonCompatibleValue(v),
],
),
);
}

if (CEL.isCelList(value)) {
return [...value].map(
(v): ReturnType<(typeof JSON)["parse"]> => toJsonCompatibleValue(v),
);
}

return value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to handle CelUint, bigint, Uint8Array, maybe also CelType and ReflectMessage: https://github.com/bufbuild/cel-es/tree/main/packages/cel#types

This could be a replacer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter
YAML stringify supports it too.

Or it could be a function in @bufbuild/cel - but then we need to be very certain about it.

Or we could just have a comment here to clarify that this function doesn't handle all possible CEL values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants