adding quotes in text response

This commit is contained in:
Pooja Belaramani 2024-12-27 11:12:46 +05:30
parent 582e8e5eac
commit 9a2d8bfff3
2 changed files with 6 additions and 4 deletions

View File

@ -27,14 +27,13 @@ const formatResponse = (data, mode, filter) => {
let isValidJSON = false; let isValidJSON = false;
try { try {
isValidJSON = isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object'
typeof JSON.parse(JSON.stringify(data)) === 'object' || typeof JSON.parse(JSON.stringify(data)) === 'string';
} catch (error) { } catch (error) {
console.log('Error parsing JSON: ', error.message); console.log('Error parsing JSON: ', error.message);
} }
if (!isValidJSON && typeof data === 'string') { if (!isValidJSON && typeof data === 'string') {
return data; return JSON.stringify(data);
} }
if (filter) { if (filter) {

View File

@ -366,7 +366,10 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
// Filter out ZWNBSP character // Filter out ZWNBSP character
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d // https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
data = data.replace(/^\uFEFF/, ''); data = data.replace(/^\uFEFF/, '');
if (!disableParsingResponseJson) { if (
!disableParsingResponseJson
&& !(data.startsWith("\"") && data.endsWith("\"")) // a quoated string is also a vaild json but we want to show it as a quoated string only (parsing removes the quoates)
) {
data = JSON.parse(data); data = JSON.parse(data);
} }
} catch { } } catch { }