MCPcopy
hub / github.com/loggerhead/json4u / parseJSON

Function parseJSON

src/lib/parser/parse.ts:21–40  ·  view source on GitHub ↗
(text: string, options?: ParseOptions, parentMeta?: ParentMeta)

Source from the content-addressed store, hash-verified

19 * @returns The parsed tree.
20 */
21export function parseJSON(text: string, options?: ParseOptions, parentMeta?: ParentMeta): Tree {
22 const { nodeMap, nestNodeMap, parseErrors } = doParseJSON(text, options, parentMeta);
23 const errors: ContextError[] =
24 parseErrors.map((e) => ({
25 ...e,
26 context: [
27 text.slice(0, e.offset).slice(-50),
28 text.slice(e.offset, e.offset + e.length),
29 text.slice(e.offset + e.length).slice(0, 50),
30 ],
31 })) ?? [];
32
33 for (const id in nodeMap) {
34 nodeMap[id].path = undefined!;
35 nodeMap[id].parent = undefined;
36 nodeMap[id].childrenOffset = undefined;
37 }
38
39 return Tree.fromObject({ nodeMap, text, errors }, nestNodeMap);
40}
41
42function doParseJSON(text: string, options?: ParseOptions, parentMeta?: ParentMeta) {
43 const visitor = new Visitor(text, options, parentMeta);

Callers 15

isEqualFunction · 0.90
urlToJSONFunction · 0.90
pythonDictToJSONFunction · 0.90
parseAndFormatFunction · 0.90
prettyFormatWithFallbackFunction · 0.90
checkTextFunction · 0.90
checkStyleFunction · 0.90
expectEqFunction · 0.90
format.bench.tsFile · 0.90
tree.test.tsFile · 0.90
expectEqFunction · 0.90
parse.test.tsFile · 0.90

Calls 2

doParseJSONFunction · 0.85
fromObjectMethod · 0.80

Tested by 6

checkTextFunction · 0.72
checkStyleFunction · 0.72
expectEqFunction · 0.72
expectEqFunction · 0.72
expectIsEqualsFunction · 0.72
checkNodesFunction · 0.72