diff --git a/locales/en.yml b/locales/en.yml index 1a869a3a..afe9e11c 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -2355,6 +2355,7 @@ tools: placeholder-put-your-string-to-unescape: Put your string to unescape... label-string-to-unescape: String to unescape label-unescaped-string: Unescaped string + label-wrap-in-quotes: Wrap in quotes json-linter: title: JSON Linter description: Check and lint JSON content diff --git a/src/tools/json-escaper/json-escaper.vue b/src/tools/json-escaper/json-escaper.vue index bd0455fc..455b469b 100644 --- a/src/tools/json-escaper/json-escaper.vue +++ b/src/tools/json-escaper/json-escaper.vue @@ -2,15 +2,20 @@ import { useI18n } from 'vue-i18n'; import { addSlashes, removeSlashes } from 'slashes'; import TextareaCopyable from '@/components/TextareaCopyable.vue'; -import { useQueryParam } from '@/composable/queryParams'; +import { useQueryParam, useQueryParamOrStorage } from '@/composable/queryParams'; const { t } = useI18n(); +const wrapInQuotes = useQueryParamOrStorage({ name: 'wrap', storageName: 'json-escaper:wrap', defaultValue: false }); const unescapedInput = useQueryParam({ tool: 'json-escaper', name: 'escape', defaultValue: '' }); const escapedOutput = computed( () => { try { - return addSlashes(unescapedInput.value); + const slashedString = addSlashes(unescapedInput.value); + if (wrapInQuotes.value) { + return `"${slashedString}"`; + } + return slashedString; } catch (e: any) { return e.toString(); @@ -41,9 +46,15 @@ const unescapedOutput = computed( raw-text multiline rows="5" - mb-5 + mb-1 /> + + + + + +