MCPcopy Create free account
hub / github.com/Web3Auth/Auth / isValidJson

Function isValidJson

src/utils/jrpc.ts:22–36  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

20 * @returns Whether the value is valid JSON.
21 */
22export function isValidJson(value: unknown): value is Json {
23 if (value === null) {
24 return true;
25 }
26 if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
27 return true;
28 }
29 if (Array.isArray(value)) {
30 return value.every((entry) => isValidJson(entry));
31 }
32 if (isObject(value)) {
33 return Object.values(value).every((entry) => isValidJson(entry));
34 }
35 return false;
36}
37
38/**
39 * JSON-stringifies a value with 2-space indentation.

Callers 1

utils.test.tsFile · 0.90

Calls 1

isObjectFunction · 0.90

Tested by

no test coverage detected