MCPcopy
hub / github.com/FlowiseAI/Flowise / parseOutput

Function parseOutput

packages/components/src/utils.ts:1556–1582  ·  view source on GitHub ↗
(output: any)

Source from the content-addressed store, hash-verified

1554 * @returns {any} - The parsed output or original output if not parseable
1555 */
1556const parseOutput = (output: any): any => {
1557 // If output is not a string, return as-is
1558 if (typeof output !== 'string') {
1559 return output
1560 }
1561
1562 // Trim whitespace
1563 const trimmedOutput = output.trim()
1564
1565 // Check if it's an empty string
1566 if (!trimmedOutput) {
1567 return output
1568 }
1569
1570 // Check if it looks like JSON (starts with { or [)
1571 if ((trimmedOutput.startsWith('{') && trimmedOutput.endsWith('}')) || (trimmedOutput.startsWith('[') && trimmedOutput.endsWith(']'))) {
1572 try {
1573 const parsedOutput = parseJsonBody(trimmedOutput)
1574 return parsedOutput
1575 } catch (e) {
1576 return output
1577 }
1578 }
1579
1580 // Return the original string if it doesn't look like JSON
1581 return output
1582}
1583
1584/**
1585 * Execute JavaScript code using either Sandbox or NodeVM

Callers 1

executeJavaScriptCodeFunction · 0.85

Calls 1

parseJsonBodyFunction · 0.85

Tested by

no test coverage detected