feat: display raw query response unformatted for readability (#2272)

* feat: display raw query response unformatted for readability

* chore: improved response json parsing

---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
Dawood F.K Morris 2024-09-11 07:49:17 +02:00 committed by GitHub
parent 0b4e9e7640
commit 087bab6fb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View File

@ -19,11 +19,23 @@ const formatResponse = (data, mode, filter) => {
}
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) {
return data;
}
if (filter) {
try {
data = JSONPath({ path: filter, json: data });
} catch (e) {
console.warn('Could not filter with JSONPath.', e.message);
console.warn('Could not apply JSONPath filter:', e.message);
}
}
@ -35,15 +47,10 @@ const formatResponse = (data, mode, filter) => {
if (typeof parsed === 'string') {
return parsed;
}
return safeStringifyJSON(parsed, true);
}
if (typeof data === 'string') {
return data;
}
return safeStringifyJSON(data);
return data;
};
const QueryResult = ({ item, collection, data, dataBuffer, width, disableRunEventListener, headers, error }) => {