Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: precision lost when json is beautified (#4086)

Nivedinbece13e6b098
diff --git a/packages/hoppscotch-common/src/components/http/RawBody.vue b/packages/hoppscotch-common/src/components/http/RawBody.vue
index a3bffd95c..8ccc5f31f 100644
--- a/packages/hoppscotch-common/src/components/http/RawBody.vue
+++ b/packages/hoppscotch-common/src/components/http/RawBody.vue
@@ -89,6 +89,7 @@ import { readFileAsText } from "~/helpers/functional/files"
import xmlFormat from "xml-formatter"
import { useNestedSetting } from "~/composables/settings"
import { toggleNestedSetting } from "~/newstore/settings"
+import * as LJSON from "lossless-json"
type PossibleContentTypes = Exclude<
ValidContentTypes,
@@ -187,8 +188,8 @@ const prettifyRequestBody = () => {
let prettifyBody = ""
try {
if (body.value.contentType.endsWith("json")) {
- const jsonObj = JSON.parse(rawParamsBody.value as string)
- prettifyBody = JSON.stringify(jsonObj, null, 2)
+ const jsonObj = LJSON.parse(rawParamsBody.value as string)
+ prettifyBody = LJSON.stringify(jsonObj, undefined, 2) as string
} else if (body.value.contentType === "application/xml") {
prettifyBody = prettifyXML(rawParamsBody.value as string)
}