MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / isJson

Function isJson

lib/embed-docs/utils.ts:160–184  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

158}
159
160export function isJson(text: string): boolean {
161 const possibleJsonChunk = getPossibleJsonChunk(text);
162 if (!possibleJsonChunk) {
163 console.log(`No possible JSON chunk found in:\n${text}`);
164 return false;
165 }
166
167 const commentLessJson = possibleJsonChunk.replace(
168 /\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
169 (m, g) => (g ? "" : m),
170 );
171
172 try {
173 JSON.parse(commentLessJson);
174 return true;
175 } catch {
176 try {
177 // Try to see if outer brackets are missing
178 JSON.parse(`[${commentLessJson}]`);
179 return true;
180 } catch {
181 return false;
182 }
183 }
184}
185
186export function unprettifyJsonString(jsonString: string): string {
187 // Convert all comments to /* */ style

Callers 1

splitOutCodeChunksFunction · 0.85

Calls 1

getPossibleJsonChunkFunction · 0.85

Tested by

no test coverage detected