Bugfix/Parse JSON correctly (#5220)

* parse JSON correctly

* add codeblock highlight
This commit is contained in:
Henry Heng
2025-09-18 19:18:50 +01:00
committed by GitHub
parent 011d60332e
commit cf6539cd3f
18 changed files with 283 additions and 69 deletions
@@ -1,10 +1,9 @@
import { Tool } from '@langchain/core/tools'
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../../src/Interface'
import { MCPToolkit, validateMCPServerConfig } from '../core'
import { getVars, prepareSandboxVars } from '../../../../src/utils'
import { getVars, prepareSandboxVars, parseJsonBody } from '../../../../src/utils'
import { DataSource } from 'typeorm'
import hash from 'object-hash'
import JSON5 from 'json5'
const mcpServerConfig = `{
"command": "npx",
@@ -270,7 +269,7 @@ function substituteVariablesInString(str: string, sandbox: any): string {
function convertToValidJSONString(inputString: string) {
try {
const jsObject = JSON5.parse(inputString)
const jsObject = parseJsonBody(inputString)
return JSON.stringify(jsObject, null, 2)
} catch (error) {
console.error('Error converting to JSON:', error)