Skip to content

Commit e897dc1

Browse files
authored
Merge pull request #3706 from Pragadesh-45/fix/response-format-updates
fix: improve JSON parsing logic for `bruno-cli`
2 parents 85b6cae + 7b935bd commit e897dc1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/bruno-cli/src/utils/common.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
3838
// Filter out ZWNBSP character
3939
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
4040
data = data.replace(/^\uFEFF/, '');
41-
if (!disableParsingResponseJson) {
41+
42+
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
43+
if (!disableParsingResponseJson && !(typeof data === 'string' && data.startsWith('"') && data.endsWith('"'))) {
4244
data = JSON.parse(data);
4345
}
44-
} catch { }
46+
} catch {
47+
console.log('Failed to parse response data as JSON');
48+
}
4549

4650
return { data, dataBuffer };
4751
};

packages/bruno-electron/src/ipc/network/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
365365
try {
366366
// Filter out ZWNBSP character
367367
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
368+
data = data.replace(/^\uFEFF/, '');
368369

369370
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
370-
data = data.replace(/^\uFEFF/, '');
371371
if ( !disableParsingResponseJson && ! (typeof data === 'string' && data.startsWith("\"") && data.endsWith("\""))) {
372372
data = JSON.parse(data);
373373
}

0 commit comments

Comments
 (0)