MCPcopy
hub / github.com/validatorjs/validator.js / isJSON

Function isJSON

src/lib/isJSON.js:10–29  ·  view source on GitHub ↗
(str, options)

Source from the content-addressed store, hash-verified

8};
9
10export default function isJSON(str, options) {
11 assertString(str);
12 try {
13 options = merge(options, default_json_options);
14 const obj = JSON.parse(str);
15
16 // When allow_any_value is true, accept anything that JSON.parse successfully parses
17 if (options.allow_any_value) {
18 return true;
19 }
20
21 let primitives = [];
22 if (options.allow_primitives) {
23 primitives = [null, false, true];
24 }
25
26 return includes(primitives, obj) || (!!obj && typeof obj === 'object');
27 } catch (e) { /* ignore */ }
28 return false;
29}

Callers

nothing calls this directly

Calls 3

assertStringFunction · 0.85
mergeFunction · 0.85
includesFunction · 0.50

Tested by

no test coverage detected