MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-workbench / parseIfValidJson

Function parseIfValidJson

src/utils/parsers.ts:4–14  ·  view source on GitHub ↗
(str: unknown)

Source from the content-addressed store, hash-verified

2import { HeaderAttributes } from "../services/models/header";
3
4export function parseIfValidJson(str: unknown) {
5 if (typeof str !== "string") return null;
6 try {
7 const parsedObj = JSON.parse(str);
8 // Return only if it is an object & not a primitive value
9 if (Object(parsedObj) === parsedObj) return parsedObj;
10 return null;
11 } catch (e) {
12 return null;
13 }
14}
15
16export enum ScanOptionKeys {
17 CLASSIFY = "--classify",

Callers 4

ScanInfoFunction · 0.90
jsonDataTypeFunction · 0.90
parsers.test.tsFile · 0.90
parseScanInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected