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

Function pythonDictToJSON

src/lib/worker/command/pythonDictToJSON.ts:5–17  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

3
4// 将 python dict 转成 JSON
5export async function pythonDictToJSON(text: string) {
6 const options = (await getConfig()).parseOptions;
7 text = text
8 .replace(/,\s*\}(\W*?)/gm, "}$1")
9 .replace(/,\s*\](\W*?)/gm, "]$1")
10 .replace(/(\W*?)'/gm, '$1"')
11 .replace(/'(\W*?)/gm, '"$1')
12 .replace(/\bTrue\b/gm, "true")
13 .replace(/\bFalse\b/gm, "false")
14 .replace(/\bNone\b/gm, "null");
15 const tree = parseJSON(text, options);
16 return tree.valid() ? tree.stringify(options) : text;
17}

Callers

nothing calls this directly

Calls 4

getConfigFunction · 0.90
parseJSONFunction · 0.90
validMethod · 0.80
stringifyMethod · 0.80

Tested by

no test coverage detected