From 938e0560a20777bf3476ffb87072ec21594f079f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20D?= <72203064+TheoD02@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:54:33 +0200 Subject: [PATCH] fix: handle case of text when invalid JSON (#3119) (#3120) * fix: handle case of text when invalid JSON (#3119) * don't stringify if json is invalid, and maintain indentation if stringified * stringify check --------- Co-authored-by: lohit --- .../src/components/ResponsePane/QueryResult/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index ccf08f3164..8b233d51ee 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -19,16 +19,20 @@ const formatResponse = (data, mode, filter) => { return ''; } + if (data === null) { + return data; + } + if (mode.includes('json')) { let isValidJSON = false; - + try { isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object'; } catch (error) { console.log('Error parsing JSON: ', error.message); } - if (!isValidJSON || data === null) { + if (!isValidJSON && typeof data === 'string') { return data; }