From 467e63d6fa72bee1d90ccece1fef598a05abc6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20=C3=96dman?= Date: Mon, 29 Jan 2024 18:59:31 +0100 Subject: [PATCH] feat: correctly format json when importing from curl (#1472) --- package-lock.json | 109 ++++++++++++------- packages/bruno-app/package.json | 3 +- packages/bruno-app/src/utils/common/index.js | 8 ++ packages/bruno-app/src/utils/curl/index.js | 4 +- 4 files changed, 83 insertions(+), 41 deletions(-) diff --git a/package-lock.json b/package-lock.json index 61b2ae415..c348d5917 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11733,8 +11733,8 @@ }, "node_modules/json5": { "version": "2.2.3", - "dev": true, - "license": "MIT", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "bin": { "json5": "lib/cli.js" }, @@ -14697,7 +14697,6 @@ }, "node_modules/react-is": { "version": "18.2.0", - "dev": true, "license": "MIT" }, "node_modules/react-pdf": { @@ -17756,6 +17755,7 @@ "immer": "^9.0.15", "jsesc": "^3.0.2", "jshint": "^2.13.6", + "json5": "^2.2.3", "jsonlint": "^1.6.3", "jsonpath-plus": "^7.2.0", "know-your-http-well": "^0.5.0", @@ -20341,7 +20341,8 @@ "version": "2.6.2" }, "ws": { - "version": "8.13.0" + "version": "8.13.0", + "requires": {} } } }, @@ -20380,7 +20381,8 @@ "version": "2.6.2" }, "ws": { - "version": "8.13.0" + "version": "8.13.0", + "requires": {} } } }, @@ -20545,7 +20547,8 @@ } }, "@graphql-typed-document-node/core": { - "version": "3.2.0" + "version": "3.2.0", + "requires": {} }, "@iarna/toml": { "version": "2.2.5" @@ -21879,7 +21882,8 @@ } }, "@tabler/icons": { - "version": "1.119.0" + "version": "1.119.0", + "requires": {} }, "@tippyjs/react": { "version": "4.2.6", @@ -22167,6 +22171,7 @@ "immer": "^9.0.15", "jsesc": "^3.0.2", "jshint": "^2.13.6", + "json5": "*", "jsonlint": "^1.6.3", "jsonpath-plus": "^7.2.0", "know-your-http-well": "^0.5.0", @@ -22456,7 +22461,8 @@ } }, "@usebruno/schema": { - "version": "file:packages/bruno-schema" + "version": "file:packages/bruno-schema", + "requires": {} }, "@usebruno/tests": { "version": "file:packages/bruno-tests", @@ -22610,7 +22616,8 @@ }, "@webpack-cli/configtest": { "version": "1.2.0", - "dev": true + "dev": true, + "requires": {} }, "@webpack-cli/info": { "version": "1.5.0", @@ -22621,7 +22628,8 @@ }, "@webpack-cli/serve": { "version": "1.7.0", - "dev": true + "dev": true, + "requires": {} }, "@whatwg-node/events": { "version": "0.0.3" @@ -22725,7 +22733,8 @@ }, "ajv-keywords": { "version": "3.5.2", - "dev": true + "dev": true, + "requires": {} }, "amdefine": { "version": "0.0.8" @@ -23640,7 +23649,8 @@ } }, "chai-string": { - "version": "1.5.0" + "version": "1.5.0", + "requires": {} }, "chalk": { "version": "4.1.2", @@ -24057,7 +24067,8 @@ }, "css-declaration-sorter": { "version": "6.3.1", - "dev": true + "dev": true, + "requires": {} }, "css-loader": { "version": "6.7.3", @@ -24176,7 +24187,8 @@ }, "cssnano-utils": { "version": "3.1.0", - "dev": true + "dev": true, + "requires": {} }, "csso": { "version": "4.2.0", @@ -25361,7 +25373,8 @@ } }, "goober": { - "version": "2.1.11" + "version": "2.1.11", + "requires": {} }, "gopd": { "version": "1.0.1", @@ -25546,7 +25559,8 @@ } }, "graphql-ws": { - "version": "5.12.1" + "version": "5.12.1", + "requires": {} }, "handlebars": { "version": "4.7.8", @@ -25831,7 +25845,8 @@ }, "icss-utils": { "version": "5.1.0", - "dev": true + "dev": true, + "requires": {} }, "idb": { "version": "7.1.1" @@ -26180,7 +26195,8 @@ "version": "3.0.1" }, "isomorphic-ws": { - "version": "5.0.0" + "version": "5.0.0", + "requires": {} }, "isstream": { "version": "0.1.2" @@ -26431,7 +26447,8 @@ }, "jest-pnp-resolver": { "version": "1.2.3", - "dev": true + "dev": true, + "requires": {} }, "jest-regex-util": { "version": "29.2.0", @@ -26769,7 +26786,8 @@ }, "json5": { "version": "2.2.3", - "dev": true + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==" }, "jsonfile": { "version": "6.1.0", @@ -27114,7 +27132,8 @@ "version": "1.0.1" }, "merge-refs": { - "version": "1.2.2" + "version": "1.2.2", + "requires": {} }, "merge-stream": { "version": "2.0.0", @@ -27124,7 +27143,8 @@ "version": "1.4.1" }, "meros": { - "version": "1.2.1" + "version": "1.2.1", + "requires": {} }, "methods": { "version": "1.1.2" @@ -27922,19 +27942,23 @@ }, "postcss-discard-comments": { "version": "5.1.2", - "dev": true + "dev": true, + "requires": {} }, "postcss-discard-duplicates": { "version": "5.1.0", - "dev": true + "dev": true, + "requires": {} }, "postcss-discard-empty": { "version": "5.1.1", - "dev": true + "dev": true, + "requires": {} }, "postcss-discard-overridden": { "version": "5.1.0", - "dev": true + "dev": true, + "requires": {} }, "postcss-js": { "version": "3.0.3", @@ -28016,7 +28040,8 @@ }, "postcss-modules-extract-imports": { "version": "3.0.0", - "dev": true + "dev": true, + "requires": {} }, "postcss-modules-local-by-default": { "version": "4.0.0", @@ -28049,7 +28074,8 @@ }, "postcss-normalize-charset": { "version": "5.1.0", - "dev": true + "dev": true, + "requires": {} }, "postcss-normalize-display-values": { "version": "5.1.0", @@ -28530,11 +28556,11 @@ } }, "react-inspector": { - "version": "6.0.2" + "version": "6.0.2", + "requires": {} }, "react-is": { - "version": "18.2.0", - "dev": true + "version": "18.2.0" }, "react-pdf": { "version": "7.5.1", @@ -28694,7 +28720,8 @@ } }, "redux-thunk": { - "version": "2.4.2" + "version": "2.4.2", + "requires": {} }, "regenerate": { "version": "1.4.2", @@ -28932,7 +28959,8 @@ }, "rollup-plugin-peer-deps-external": { "version": "2.2.4", - "dev": true + "dev": true, + "requires": {} }, "rollup-plugin-postcss": { "version": "4.0.2", @@ -29442,7 +29470,8 @@ }, "style-loader": { "version": "3.3.1", - "dev": true + "dev": true, + "requires": {} }, "style-mod": { "version": "4.1.0" @@ -29474,7 +29503,8 @@ } }, "styled-jsx": { - "version": "5.0.7" + "version": "5.0.7", + "requires": {} }, "stylehacks": { "version": "5.1.1", @@ -30114,7 +30144,8 @@ "version": "8.0.2" }, "use-sync-external-store": { - "version": "1.2.0" + "version": "1.2.0", + "requires": {} }, "utf8-byte-length": { "version": "1.0.4", @@ -30284,7 +30315,8 @@ }, "acorn-import-assertions": { "version": "1.8.0", - "dev": true + "dev": true, + "requires": {} }, "schema-utils": { "version": "3.1.1", @@ -30385,7 +30417,8 @@ } }, "ws": { - "version": "8.16.0" + "version": "8.16.0", + "requires": {} }, "xdg-basedir": { "version": "4.0.0", diff --git a/packages/bruno-app/package.json b/packages/bruno-app/package.json index 63708ce04..325304ec6 100644 --- a/packages/bruno-app/package.json +++ b/packages/bruno-app/package.json @@ -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", diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js index 34a068e6d..e19d848d6 100644 --- a/packages/bruno-app/src/utils/common/index.js +++ b/packages/bruno-app/src/utils/common/index.js @@ -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; diff --git a/packages/bruno-app/src/utils/curl/index.js b/packages/bruno-app/src/utils/curl/index.js index b88f93ce8..97bfbd966 100644 --- a/packages/bruno-app/src/utils/curl/index.js +++ b/packages/bruno-app/src/utils/curl/index.js @@ -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;