json xml texts

This commit is contained in:
steffenrapp 2024-09-05 16:46:55 +00:00
parent f5a5ca6550
commit c756058c5c
4 changed files with 26 additions and 8 deletions

View file

@ -487,9 +487,17 @@ tools:
json-to-xml: json-to-xml:
title: JSON zu XML title: JSON zu XML
description: JSON in XML konvertieren description: JSON in XML konvertieren
input: Dein JSON-Inhalt
input-placeholder: Füge hier deinen JSON-Inhalt ein...
output: Konvertiertes XML
error: Bereitgestelltes JSON ist ungültig.
xml-to-json: xml-to-json:
title: XML zu JSON title: XML zu JSON
description: XML in JSON konvertieren description: XML in JSON konvertieren
input: Dein XML-Inhalt
input-placeholder: Füge hier deinen XML-Inhalt ein...
output: Konvertiertes JSON
error: Bereitgestelltes XML ist ungültig.
email-normalizer: email-normalizer:
title: E-Mail-Normalisierung title: E-Mail-Normalisierung
description: >- description: >-

View file

@ -456,9 +456,17 @@ tools:
json-to-xml: json-to-xml:
title: JSON to XML title: JSON to XML
description: Convert JSON to XML description: Convert JSON to XML
input: Your JSON content
input-placeholder: Paste your JSON content here...
output: Converted XML
error: Provided JSON is not valid.
xml-to-json: xml-to-json:
title: XML to JSON title: XML to JSON
description: Convert XML to JSON description: Convert XML to JSON
input: Your XML content
input-placeholder: Paste your XML content here...
output: Converted JSON
error: Provided XML is not valid.
email-normalizer: email-normalizer:
title: Email normalizer title: Email normalizer
description: >- description: >-

View file

@ -4,6 +4,7 @@ import JSON5 from 'json5';
import { withDefaultOnError } from '@/utils/defaults'; import { withDefaultOnError } from '@/utils/defaults';
import type { UseValidationRule } from '@/composable/validation'; import type { UseValidationRule } from '@/composable/validation';
const { t } = useI18n();
const defaultValue = '{"a":{"_attributes":{"x":"1.234","y":"It\'s"}}}'; const defaultValue = '{"a":{"_attributes":{"x":"1.234","y":"It\'s"}}}';
function transformer(value: string) { function transformer(value: string) {
return withDefaultOnError(() => { return withDefaultOnError(() => {
@ -14,17 +15,17 @@ function transformer(value: string) {
const rules: UseValidationRule<string>[] = [ const rules: UseValidationRule<string>[] = [
{ {
validator: (v: string) => v === '' || JSON5.parse(v), validator: (v: string) => v === '' || JSON5.parse(v),
message: 'Provided JSON is not valid.', message: t('tools.json-to-xml.error'),
}, },
]; ];
</script> </script>
<template> <template>
<format-transformer <format-transformer
input-label="Your JSON content" :input-label="t('tools.json-to-xml.input')"
:input-default="defaultValue" :input-default="defaultValue"
input-placeholder="Paste your JSON content here..." :input-placeholder="t('tools.json-to-xml.input-placeholder')"
output-label="Converted XML" :output-label="t('tools.json-to-xml.output')"
output-language="xml" output-language="xml"
:transformer="transformer" :transformer="transformer"
:input-validation-rules="rules" :input-validation-rules="rules"

View file

@ -4,6 +4,7 @@ import { isValidXML } from '../xml-formatter/xml-formatter.service';
import { withDefaultOnError } from '@/utils/defaults'; import { withDefaultOnError } from '@/utils/defaults';
import type { UseValidationRule } from '@/composable/validation'; import type { UseValidationRule } from '@/composable/validation';
const { t } = useI18n();
const defaultValue = '<a x="1.234" y="It\'s"/>'; const defaultValue = '<a x="1.234" y="It\'s"/>';
function transformer(value: string) { function transformer(value: string) {
return withDefaultOnError(() => { return withDefaultOnError(() => {
@ -14,17 +15,17 @@ function transformer(value: string) {
const rules: UseValidationRule<string>[] = [ const rules: UseValidationRule<string>[] = [
{ {
validator: isValidXML, validator: isValidXML,
message: 'Provided XML is not valid.', message: t('tools.xml-to-json.error'),
}, },
]; ];
</script> </script>
<template> <template>
<format-transformer <format-transformer
input-label="Your XML content" :input-label="t('tools.xml-to-json.input')"
:input-default="defaultValue" :input-default="defaultValue"
input-placeholder="Paste your XML content here..." :input-placeholder="t('tools.xml-to-json.input-placeholder')"
output-label="Converted JSON" :output-label="t('tools.xml-to-json.output')"
output-language="json" output-language="json"
:transformer="transformer" :transformer="transformer"
:input-validation-rules="rules" :input-validation-rules="rules"