From 8d8f8abaf3b893a9f5b0a94ffd44da8b2eb1931a Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 7 Dec 2025 18:31:07 +0100 Subject: [PATCH] added method fixJsonBraces, see #551. --- js/mzta-utils.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/js/mzta-utils.js b/js/mzta-utils.js index 24cb954c..135d7616 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -592,8 +592,11 @@ export function hasSpecificIntegration(use, conntype){ return use && (conntype != null) && (conntype !== ''); } -export function extractJsonObject(inputString) { +export function extractJsonObject(inputString, fixBraces = true) { try { + if (fixBraces) { + inputString = fixJsonBraces(inputString); + } const jsonMatch = inputString.match(/\{[\s\S]*\}/); if (jsonMatch) { const jsonObject = JSON.parse(jsonMatch[0]); @@ -611,6 +614,23 @@ export function extractJsonObject(inputString) { } } +function fixJsonBraces(inputString) { + let result = inputString.trim(); + const hasOpen = result.startsWith("{"); + const hasClose = result.endsWith("}"); + + if (hasClose && !hasOpen) { + return "{" + result; + } + + if (hasOpen && !hasClose) { + return result + "}"; + } + + return result; +} + + export function isAPIKeyValue(id){ return id=="chatgpt_api_key" || id=="openai_comp_api_key" || id=="google_gemini_api_key" || id=="anthropic_api_key"; }