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: curl parser json detection issues (#2370)

kyteinskyc1cc1ce2955d
diff --git a/packages/hoppscotch-app/helpers/curl/sub_helpers/contentParser.ts b/packages/hoppscotch-app/helpers/curl/sub_helpers/contentParser.ts
index 74cbc0c45..6ca7206fd 100644
--- a/packages/hoppscotch-app/helpers/curl/sub_helpers/contentParser.ts
+++ b/packages/hoppscotch-app/helpers/curl/sub_helpers/contentParser.ts
@@ -158,14 +158,11 @@ const getXMLBody = (rawData: string) =>
O.alt(() => O.some(rawData))
)
-const getFormattedJSON = (jsonString: string) =>
- pipe(
- jsonString.replaceAll('\\"', '"'),
- safeParseJSON,
- O.map((parsedJSON) => JSON.stringify(parsedJSON, null, 2)),
- O.getOrElse(() => "{ }"),
- O.of
- )
+const getFormattedJSON = flow(
+ safeParseJSON,
+ O.map((parsedJSON) => JSON.stringify(parsedJSON, null, 2)),
+ O.getOrElse(() => "{ }")
+)
const getXWWWFormUrlEncodedBody = flow(
decodeURIComponent,
@@ -191,7 +188,7 @@ export function parseBody(
case "application/ld+json":
case "application/vnd.api+json":
case "application/json":
- return getFormattedJSON(rawData)
+ return O.some(getFormattedJSON(rawData))
case "application/x-www-form-urlencoded":
return getXWWWFormUrlEncodedBody(rawData)