MCPcopy Create free account
hub / github.com/zxlie/FeHelper / normalizeLooseJSONSource

Function normalizeLooseJSONSource

apps/json-format/json-utils.js:134–148  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

132}
133
134function normalizeLooseJSONSource(text) {
135 let fixed = String(text).trim();
136
137 fixed = replaceOutsideQuotedSegments(fixed, /([\{,]\s*)'([^'\\]*?)'(\s*:)/g, function (match, prefix, key, suffix) {
138 return prefix + '"' + key + '"' + suffix;
139 });
140 fixed = replaceOutsideQuotedSegments(fixed, /([\{,]\s*)(\w+)(\s*:)/g, function (match, prefix, key, suffix) {
141 return prefix + '"' + key + '"' + suffix;
142 });
143 fixed = replaceOutsideQuotedSegments(fixed, /(:\s*)'([^'\\]*?)'/g, function (match, prefix, value) {
144 return prefix + '"' + value + '"';
145 });
146
147 return fixed;
148}
149
150export function isIntegerIndexKey(key) {
151 if (typeof key !== 'string' || !/^(0|[1-9]\d*)$/.test(key)) return false;

Callers 1

parseWithBigIntFunction · 0.70

Calls 1

Tested by

no test coverage detected