Revert "Fix: Prettify JSON for Res-preview without parsing to avoid JS specific roundings"

This reverts commit 56581b3641.
This commit is contained in:
ramki-bruno
2025-03-25 21:13:51 +05:30
committed by Anoop M D
parent ccd4a14da6
commit 7622a4aaae
2 changed files with 3 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ import QueryResultPreview from './QueryResultPreview';
import StyledWrapper from './StyledWrapper';
import { useState, useMemo, useEffect } from 'react';
import { useTheme } from 'providers/Theme/index';
import { getEncoding, prettifyJson, uuid } from 'utils/common/index';
import { getEncoding, uuid } from 'utils/common/index';
const formatResponse = (data, dataBuffer, encoding, mode, filter) => {
if (data === undefined || !dataBuffer) {
@@ -37,15 +37,12 @@ const formatResponse = (data, dataBuffer, encoding, mode, filter) => {
if (filter) {
try {
data = JSONPath({ path: filter, json: data });
return prettifyJson(JSON.stringify(data));
} catch (e) {
console.warn('Could not apply JSONPath filter:', e.message);
}
}
// Prettify the JSON string directly instead of parse->stringify to avoid
// issues like rounding numbers bigger than Number.MAX_SAFE_INTEGER etc.
return prettifyJson(rawData);
return safeStringifyJSON(data, true);
}
if (mode.includes('xml')) {
@@ -60,7 +57,7 @@ const formatResponse = (data, dataBuffer, encoding, mode, filter) => {
return data;
}
return prettifyJson(rawData);
return safeStringifyJSON(data, true);
};
const formatErrorMessage = (error) => {

View File

@@ -1,6 +1,5 @@
import { customAlphabet } from 'nanoid';
import xmlFormat from 'xml-formatter';
import { format as jsoncFormat, applyEdits as jsoncApplyEdits } from 'jsonc-parser';
// a customized version of nanoid without using _ and -
export const uuid = () => {
@@ -27,13 +26,6 @@ export const waitForNextTick = () => {
});
};
export const prettifyJson = (doc) => {
return jsoncApplyEdits(
doc,
jsoncFormat(doc, null, {insertSpaces: true, tabSize: 2})
);
}
export const safeParseJSON = (str) => {
if (!str || !str.length || typeof str !== 'string') {
return str;