MCPcopy Create free account
hub / github.com/SethGammon/Citadel / parseJsonValues

Function parseJsonValues

scripts/codex-review-fetch.js:28–76  ·  view source on GitHub ↗
(raw)

Source from the content-addressed store, hash-verified

26}
27
28function parseJsonValues(raw) {
29 const text = String(raw || '').trim();
30 if (!text) return [];
31 try {
32 const parsed = JSON.parse(text);
33 return Array.isArray(parsed) ? parsed : [parsed];
34 } catch {
35 // gh --paginate can emit adjacent JSON pages. Decode them without assuming line boundaries.
36 }
37
38 const values = [];
39 let i = 0;
40 while (i < text.length) {
41 while (/\s/.test(text[i])) i += 1;
42 const start = i;
43 const opener = text[i];
44 const closer = opener === '[' ? ']' : (opener === '{' ? '}' : null);
45 if (!closer) throw new Error(`Expected JSON value at offset ${i}`);
46
47 let depth = 0;
48 let inString = false;
49 let escaped = false;
50 for (; i < text.length; i += 1) {
51 const ch = text[i];
52 if (inString) {
53 if (escaped) {
54 escaped = false;
55 } else if (ch === '\\') {
56 escaped = true;
57 } else if (ch === '"') {
58 inString = false;
59 }
60 } else if (ch === '"') {
61 inString = true;
62 } else if (ch === opener) {
63 depth += 1;
64 } else if (ch === closer) {
65 depth -= 1;
66 if (depth === 0) {
67 i += 1;
68 const parsed = JSON.parse(text.slice(start, i));
69 values.push(...(Array.isArray(parsed) ? parsed : [parsed]));
70 break;
71 }
72 }
73 }
74 }
75 return values;
76}
77
78function sourceForArgs(args) {
79 const pathArg = args.find((value) => value.startsWith('repos/')) || '';

Callers 2

fetchWithGhFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected