MCPcopy Create free account
hub / github.com/Effect-TS/effect / formatJson

Function formatJson

packages/effect/src/Formatter.ts:284–312  ·  view source on GitHub ↗
(input: unknown, options?: {
  readonly space?: number | string | undefined
})

Source from the content-addressed store, hash-verified

282 * @since 4.0.0
283 */
284export function formatJson(input: unknown, options?: {
285 readonly space?: number | string | undefined
286}): string {
287 const ancestors: Array<object> = []
288 return JSON.stringify(
289 input,
290 function(this: object, key: string, value: unknown) {
291 const original = Object.getOwnPropertyDescriptor(this, key)?.value
292 const redacted = Predicate.hasProperty(original, symbolRedactable)
293 ? redact(original)
294 : redact(value)
295 if (typeof redacted === "bigint") {
296 return format(redacted)
297 }
298 if (typeof redacted !== "object" || redacted === null) {
299 return redacted
300 }
301 while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
302 ancestors.pop()
303 }
304 if (ancestors.includes(redacted)) {
305 return undefined // circular reference
306 }
307 ancestors.push(redacted)
308 return redacted
309 },
310 options?.space
311 ) ?? "null"
312}

Callers 5

Formatter.test.tsFile · 0.90
toStringUnknownFunction · 0.90
encodeUnknownAsJsonFunction · 0.90
causePrettyErrorFunction · 0.90
causePrettyMessageFunction · 0.90

Calls 3

redactFunction · 0.90
pushMethod · 0.80
formatFunction · 0.70

Tested by

no test coverage detected