MCPcopy
hub / github.com/redpanda-data/console / toJson

Function toJson

frontend/src/utils/json-utils.ts:30–54  ·  view source on GitHub ↗
(obj: unknown, space?: string | number | undefined)

Source from the content-addressed store, hash-verified

28const seen = new Set();
29// Serialize object to json, handling reference loops gracefully
30export function toJson(obj: unknown, space?: string | number | undefined): string {
31 seen.clear();
32 try {
33 return JSON.stringify(
34 obj,
35 (_key: string, value: unknown) => {
36 if (typeof value === 'object' && value !== null) {
37 if (seen.has(value)) {
38 return;
39 }
40 seen.add(value);
41 }
42
43 if (value instanceof Error) {
44 return value.toString();
45 }
46
47 return value;
48 },
49 space
50 );
51 } finally {
52 seen.clear();
53 }
54}
55// Clone object using serialization
56
57export function clone<T>(obj: T): T {

Callers 15

renderKafkaErrorFunction · 0.90
flatResourceListFunction · 0.90
saveMessagesFunction · 0.90
setTrafficLimitMethod · 0.90
computeIdMethod · 0.90
checkArgumentsFunction · 0.90
setPageMethod · 0.90
onApplyEditMethod · 0.90
renderMethod · 0.90
componentDidCatchMethod · 0.90
env.tsFile · 0.90

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…