mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-26 22:25:40 +00:00
feat: correctly format json when importing from curl (#1472)
This commit is contained in:
@@ -39,9 +39,10 @@
|
||||
"idb": "^7.0.0",
|
||||
"immer": "^9.0.15",
|
||||
"jsesc": "^3.0.2",
|
||||
"jsonpath-plus": "^7.2.0",
|
||||
"jshint": "^2.13.6",
|
||||
"json5": "^2.2.3",
|
||||
"jsonlint": "^1.6.3",
|
||||
"jsonpath-plus": "^7.2.0",
|
||||
"know-your-http-well": "^0.5.0",
|
||||
"lodash": "^4.17.21",
|
||||
"markdown-it": "^13.0.2",
|
||||
|
||||
@@ -51,6 +51,14 @@ export const safeStringifyJSON = (obj, indent = false) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const convertToCodeMirrorJson = (obj) => {
|
||||
try {
|
||||
return JSON5.stringify(obj).slice(1, -1);
|
||||
} catch (e) {
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
export const safeParseXML = (str, options) => {
|
||||
if (!str || !str.length || typeof str !== 'string') {
|
||||
return str;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { forOwn } from 'lodash';
|
||||
import { safeStringifyJSON } from 'utils/common';
|
||||
import { convertToCodeMirrorJson } from 'utils/common';
|
||||
import curlToJson from './curl-to-json';
|
||||
|
||||
export const getRequestFromCurlCommand = (curlCommand) => {
|
||||
@@ -37,7 +37,7 @@ export const getRequestFromCurlCommand = (curlCommand) => {
|
||||
if (parsedBody && contentType && typeof contentType === 'string') {
|
||||
if (contentType.includes('application/json')) {
|
||||
body.mode = 'json';
|
||||
body.json = safeStringifyJSON(parsedBody);
|
||||
body.json = convertToCodeMirrorJson(parsedBody);
|
||||
} else if (contentType.includes('text/xml')) {
|
||||
body.mode = 'xml';
|
||||
body.xml = parsedBody;
|
||||
|
||||
Reference in New Issue
Block a user