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

Function deepParseJSONStrings

apps/json-format/json-utils.js:239–271  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

237
238// ─── 深度解包嵌套 JSON 字符串 ──────────────────────────────
239export function deepParseJSONStrings(obj) {
240 if (Array.isArray(obj)) {
241 return obj.map((item) => {
242 if (typeof item === 'string' && item.trim()) {
243 try {
244 const parsed = JSON.parse(item);
245 if (_isDeepParsable(parsed)) {
246 return deepParseJSONStrings(parsed);
247 }
248 } catch (_) {}
249 }
250 return deepParseJSONStrings(item);
251 });
252 }
253 if (typeof obj === 'object' && obj !== null) {
254 const newObj = {};
255 for (const key of Object.keys(obj)) {
256 const val = obj[key];
257 if (typeof val === 'string' && val.trim()) {
258 try {
259 const parsed = JSON.parse(val);
260 if (_isDeepParsable(parsed)) {
261 newObj[key] = deepParseJSONStrings(parsed);
262 continue;
263 }
264 } catch (_) {}
265 }
266 newObj[key] = deepParseJSONStrings(val);
267 }
268 return newObj;
269 }
270 return obj;
271}
272
273export function unpackTopLevelEscapedJSON(value) {
274 if (typeof value !== 'string' || !value.trim()) return value;

Callers 1

Calls 2

_isDeepParsableFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected