fix: prettify JSON request body with comments (#4399)

Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
Anwarul Islam
2024-10-03 19:26:01 +06:00
committed by GitHub
parent 8535004023
commit a283edec6e
3 changed files with 423 additions and 62 deletions

View File

@@ -104,8 +104,8 @@ 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"
import { useAIExperiments } from "~/composables/ai-experiments"
import { prettifyJSONC } from "~/helpers/editor/linting/jsoncPretty"
type PossibleContentTypes = Exclude<
ValidContentTypes,
@@ -205,8 +205,7 @@ const prettifyRequestBody = () => {
let prettifyBody = ""
try {
if (body.value.contentType.endsWith("json")) {
const jsonObj = LJSON.parse(rawParamsBody.value as string)
prettifyBody = LJSON.stringify(jsonObj, undefined, 2) as string
prettifyBody = prettifyJSONC(rawParamsBody.value as string)
} else if (body.value.contentType === "application/xml") {
prettifyBody = prettifyXML(rawParamsBody.value as string)
}