Fix: Revert selective JSON parsing where string response is not parsed

- Revert "Merge pull request #3706 from Pragadesh-45/fix/response-format-updates"
  - e897dc1eb0
- Revert "Merge pull request #3676 from pooja-bruno/fix/string-json-response"
  - 1f2bee1f90
This commit is contained in:
ramki-bruno
2025-03-11 00:03:28 +05:30
parent 0fbbe8a996
commit e56e5ed7ee
3 changed files with 6 additions and 14 deletions

View File

@@ -17,14 +17,14 @@ const formatResponse = (data, mode, filter) => {
}
if (data === null) {
return 'null';
return data;
}
if (mode.includes('json')) {
let isValidJSON = false;
try {
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object'
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object';
} catch (error) {
console.log('Error parsing JSON: ', error.message);
}

View File

@@ -34,14 +34,10 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
// Filter out ZWNBSP character
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
data = data.replace(/^\uFEFF/, '');
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
if (!disableParsingResponseJson && !(typeof data === 'string' && data.startsWith('"') && data.endsWith('"'))) {
if (!disableParsingResponseJson) {
data = JSON.parse(data);
}
} catch {
}
} catch { }
return { data, dataBuffer };
};

View File

@@ -398,14 +398,10 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
// Filter out ZWNBSP character
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
data = data.replace(/^\uFEFF/, '');
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
if ( !disableParsingResponseJson && ! (typeof data === 'string' && data.startsWith("\"") && data.endsWith("\""))) {
if (!disableParsingResponseJson) {
data = JSON.parse(data);
}
} catch {
console.log('Failed to parse response data as JSON');
}
} catch { }
return { data, dataBuffer };
};