MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / parseJSON

Function parseJSON

botasaurus-controls/src/index.ts:471–490  ·  view source on GitHub ↗
(value: any)

Source from the content-addressed store, hash-verified

469 return helpfulMessage
470}
471function parseJSON(value: any): { parsed: any; error: string | null } {
472 if (typeof value !== 'string') {
473 return { parsed: value, error: null };
474 }
475
476 const trimmedValue = value.trim();
477 if (trimmedValue === '') {
478 return { parsed: null, error: null };
479 }
480
481 try {
482 const parsed = JSON.parse(trimmedValue);
483 return { parsed, error: null };
484 } catch (e: any) {
485 // Provide helpful error messages based on common JSON mistakes
486 let helpfulMessage = createHelpfulJsonError(e, trimmedValue)
487
488 return { parsed: null, error: helpfulMessage };
489 }
490}
491
492class Controls {
493 private isSectionControl = false;

Callers 2

normalizeControlValueFunction · 0.85
validateMethod · 0.85

Calls 2

createHelpfulJsonErrorFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected