mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01:00
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:
parent
0b4e9e7640
commit
087bab6fb4
2
package-lock.json
generated
2
package-lock.json
generated
@ -18862,4 +18862,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,11 +19,23 @@ const formatResponse = (data, mode, filter) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mode.includes('json')) {
|
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) {
|
if (filter) {
|
||||||
try {
|
try {
|
||||||
data = JSONPath({ path: filter, json: data });
|
data = JSONPath({ path: filter, json: data });
|
||||||
} catch (e) {
|
} 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') {
|
if (typeof parsed === 'string') {
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return safeStringifyJSON(parsed, true);
|
return safeStringifyJSON(parsed, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof data === 'string') {
|
return data;
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return safeStringifyJSON(data);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const QueryResult = ({ item, collection, data, dataBuffer, width, disableRunEventListener, headers, error }) => {
|
const QueryResult = ({ item, collection, data, dataBuffer, width, disableRunEventListener, headers, error }) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user