feat(new tools): JSON to XML and XML to JSON (#1231)
* feat(new tool): JSON <> XML Fix https://github.com/CorentinTh/it-tools/issues/314 * Update src/tools/xml-to-json/index.ts * Update src/tools/json-to-xml/index.ts * Update src/tools/json-to-xml/index.ts --------- Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
This commit is contained in:
		
							parent
							
								
									e1b4f9aafe
								
							
						
					
					
						commit
						f1a5489e21
					
				
							
								
								
									
										9
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -110,6 +110,7 @@ declare module '@vue/runtime-core' { | ||||
|     JsonMinify: typeof import('./src/tools/json-minify/json-minify.vue')['default'] | ||||
|     JsonToCsv: typeof import('./src/tools/json-to-csv/json-to-csv.vue')['default'] | ||||
|     JsonToToml: typeof import('./src/tools/json-to-toml/json-to-toml.vue')['default'] | ||||
|     JsonToXml: typeof import('./src/tools/json-to-xml/json-to-xml.vue')['default'] | ||||
|     JsonToYaml: typeof import('./src/tools/json-to-yaml-converter/json-to-yaml.vue')['default'] | ||||
|     JsonViewer: typeof import('./src/tools/json-viewer/json-viewer.vue')['default'] | ||||
|     JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default'] | ||||
| @ -130,21 +131,14 @@ declare module '@vue/runtime-core' { | ||||
|     NCode: typeof import('naive-ui')['NCode'] | ||||
|     NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] | ||||
|     NConfigProvider: typeof import('naive-ui')['NConfigProvider'] | ||||
|     NDivider: typeof import('naive-ui')['NDivider'] | ||||
|     NEllipsis: typeof import('naive-ui')['NEllipsis'] | ||||
|     NFormItem: typeof import('naive-ui')['NFormItem'] | ||||
|     NGi: typeof import('naive-ui')['NGi'] | ||||
|     NGrid: typeof import('naive-ui')['NGrid'] | ||||
|     NH1: typeof import('naive-ui')['NH1'] | ||||
|     NH3: typeof import('naive-ui')['NH3'] | ||||
|     NIcon: typeof import('naive-ui')['NIcon'] | ||||
|     NInputNumber: typeof import('naive-ui')['NInputNumber'] | ||||
|     NLabel: typeof import('naive-ui')['NLabel'] | ||||
|     NLayout: typeof import('naive-ui')['NLayout'] | ||||
|     NLayoutSider: typeof import('naive-ui')['NLayoutSider'] | ||||
|     NMenu: typeof import('naive-ui')['NMenu'] | ||||
|     NScrollbar: typeof import('naive-ui')['NScrollbar'] | ||||
|     NSpin: typeof import('naive-ui')['NSpin'] | ||||
|     NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] | ||||
|     OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] | ||||
|     PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] | ||||
| @ -186,6 +180,7 @@ declare module '@vue/runtime-core' { | ||||
|     UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default'] | ||||
|     WifiQrCodeGenerator: typeof import('./src/tools/wifi-qr-code-generator/wifi-qr-code-generator.vue')['default'] | ||||
|     XmlFormatter: typeof import('./src/tools/xml-formatter/xml-formatter.vue')['default'] | ||||
|     XmlToJson: typeof import('./src/tools/xml-to-json/xml-to-json.vue')['default'] | ||||
|     YamlToJson: typeof import('./src/tools/yaml-to-json-converter/yaml-to-json.vue')['default'] | ||||
|     YamlToToml: typeof import('./src/tools/yaml-to-toml/yaml-to-toml.vue')['default'] | ||||
|     YamlViewer: typeof import('./src/tools/yaml-viewer/yaml-viewer.vue')['default'] | ||||
|  | ||||
| @ -92,6 +92,7 @@ | ||||
|     "vue-router": "^4.1.6", | ||||
|     "vue-tsc": "^1.8.1", | ||||
|     "xml-formatter": "^3.3.2", | ||||
|     "xml-js": "^1.6.11", | ||||
|     "yaml": "^2.2.1" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|  | ||||
							
								
								
									
										35
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										35
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							| @ -176,6 +176,9 @@ dependencies: | ||||
|   xml-formatter: | ||||
|     specifier: ^3.3.2 | ||||
|     version: 3.3.2 | ||||
|   xml-js: | ||||
|     specifier: ^1.6.11 | ||||
|     version: 1.6.11 | ||||
|   yaml: | ||||
|     specifier: ^2.2.1 | ||||
|     version: 2.2.1 | ||||
| @ -3354,7 +3357,7 @@ packages: | ||||
|     dependencies: | ||||
|       '@unhead/dom': 0.5.1 | ||||
|       '@unhead/schema': 0.5.1 | ||||
|       '@vueuse/shared': 10.8.0(vue@3.3.4) | ||||
|       '@vueuse/shared': 10.11.1(vue@3.3.4) | ||||
|       unhead: 0.5.1 | ||||
|       vue: 3.3.4 | ||||
|     transitivePeerDependencies: | ||||
| @ -3987,19 +3990,19 @@ packages: | ||||
|       - vue | ||||
|     dev: false | ||||
| 
 | ||||
|   /@vueuse/shared@10.3.0(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-kGqCTEuFPMK4+fNWy6dUOiYmxGcUbtznMwBZLC1PubidF4VZY05B+Oht7Jh7/6x4VOWGpvu3R37WHi81cKpiqg==} | ||||
|   /@vueuse/shared@10.11.1(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-LHpC8711VFZlDaYUXEBbFBCQ7GS3dVU9mjOhhMhXP6txTV4EhYQg/KGnQuvt/sPAtoUKq7VVUnL6mVtFoL42sA==} | ||||
|     dependencies: | ||||
|       vue-demi: 0.14.5(vue@3.3.4) | ||||
|       vue-demi: 0.14.10(vue@3.3.4) | ||||
|     transitivePeerDependencies: | ||||
|       - '@vue/composition-api' | ||||
|       - vue | ||||
|     dev: false | ||||
| 
 | ||||
|   /@vueuse/shared@10.8.0(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-dUdy6zwHhULGxmr9YUg8e+EnB39gcM4Fe2oKBSrh3cOsV30JcMPtsyuspgFCUo5xxFNaeMf/W2yyKfST7Bg8oQ==} | ||||
|   /@vueuse/shared@10.3.0(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-kGqCTEuFPMK4+fNWy6dUOiYmxGcUbtznMwBZLC1PubidF4VZY05B+Oht7Jh7/6x4VOWGpvu3R37WHi81cKpiqg==} | ||||
|     dependencies: | ||||
|       vue-demi: 0.14.7(vue@3.3.4) | ||||
|       vue-demi: 0.14.5(vue@3.3.4) | ||||
|     transitivePeerDependencies: | ||||
|       - '@vue/composition-api' | ||||
|       - vue | ||||
| @ -7959,8 +7962,6 @@ packages: | ||||
|   /sax@1.2.4: | ||||
|     resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==} | ||||
|     requiresBuild: true | ||||
|     dev: true | ||||
|     optional: true | ||||
| 
 | ||||
|   /saxes@6.0.0: | ||||
|     resolution: {integrity: sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==} | ||||
| @ -9143,8 +9144,8 @@ packages: | ||||
|       vue: 3.3.4 | ||||
|     dev: false | ||||
| 
 | ||||
|   /vue-demi@0.14.5(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-o9NUVpl/YlsGJ7t+xuqJKx8EBGf1quRhCiT6D/J0pfwmk9zUwYkC7yrF4SZCe6fETvSM3UNL2edcbYrSyc4QHA==} | ||||
|   /vue-demi@0.14.10(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==} | ||||
|     engines: {node: '>=12'} | ||||
|     hasBin: true | ||||
|     requiresBuild: true | ||||
| @ -9158,8 +9159,8 @@ packages: | ||||
|       vue: 3.3.4 | ||||
|     dev: false | ||||
| 
 | ||||
|   /vue-demi@0.14.7(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-EOG8KXDQNwkJILkx/gPcoL/7vH+hORoBaKgGe+6W7VFMvCYJfmF2dGbvgDroVnI8LU7/kTu8mbjRZGBU1z9NTA==} | ||||
|   /vue-demi@0.14.5(vue@3.3.4): | ||||
|     resolution: {integrity: sha512-o9NUVpl/YlsGJ7t+xuqJKx8EBGf1quRhCiT6D/J0pfwmk9zUwYkC7yrF4SZCe6fETvSM3UNL2edcbYrSyc4QHA==} | ||||
|     engines: {node: '>=12'} | ||||
|     hasBin: true | ||||
|     requiresBuild: true | ||||
| @ -9449,6 +9450,7 @@ packages: | ||||
| 
 | ||||
|   /workbox-google-analytics@7.0.0: | ||||
|     resolution: {integrity: sha512-MEYM1JTn/qiC3DbpvP2BVhyIH+dV/5BjHk756u9VbwuAhu0QHyKscTnisQuz21lfRpOwiS9z4XdqeVAKol0bzg==} | ||||
|     deprecated: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained | ||||
|     dependencies: | ||||
|       workbox-background-sync: 7.0.0 | ||||
|       workbox-core: 7.0.0 | ||||
| @ -9549,6 +9551,13 @@ packages: | ||||
|       xml-parser-xo: 4.0.5 | ||||
|     dev: false | ||||
| 
 | ||||
|   /xml-js@1.6.11: | ||||
|     resolution: {integrity: sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==} | ||||
|     hasBin: true | ||||
|     dependencies: | ||||
|       sax: 1.2.4 | ||||
|     dev: false | ||||
| 
 | ||||
|   /xml-name-validator@4.0.0: | ||||
|     resolution: {integrity: sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==} | ||||
|     engines: {node: '>=12'} | ||||
|  | ||||
| @ -6,6 +6,8 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer'; | ||||
| 
 | ||||
| import { tool as textToUnicode } from './text-to-unicode'; | ||||
| import { tool as safelinkDecoder } from './safelink-decoder'; | ||||
| import { tool as xmlToJson } from './xml-to-json'; | ||||
| import { tool as jsonToXml } from './json-to-xml'; | ||||
| import { tool as pdfSignatureChecker } from './pdf-signature-checker'; | ||||
| import { tool as numeronymGenerator } from './numeronym-generator'; | ||||
| import { tool as macAddressGenerator } from './mac-address-generator'; | ||||
| @ -107,6 +109,8 @@ export const toolsByCategory: ToolCategory[] = [ | ||||
|       listConverter, | ||||
|       tomlToJson, | ||||
|       tomlToYaml, | ||||
|       xmlToJson, | ||||
|       jsonToXml, | ||||
|     ], | ||||
|   }, | ||||
|   { | ||||
|  | ||||
							
								
								
									
										12
									
								
								src/tools/json-to-xml/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/tools/json-to-xml/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| import { Braces } from '@vicons/tabler'; | ||||
| import { defineTool } from '../tool'; | ||||
| 
 | ||||
| export const tool = defineTool({ | ||||
|   name: 'JSON to XML', | ||||
|   path: '/json-to-xml', | ||||
|   description: 'Convert JSON to XML', | ||||
|   keywords: ['json', 'xml'], | ||||
|   component: () => import('./json-to-xml.vue'), | ||||
|   icon: Braces, | ||||
|   createdAt: new Date('2024-08-09'), | ||||
| }); | ||||
							
								
								
									
										32
									
								
								src/tools/json-to-xml/json-to-xml.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/tools/json-to-xml/json-to-xml.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
| <script setup lang="ts"> | ||||
| import convert from 'xml-js'; | ||||
| import JSON5 from 'json5'; | ||||
| import { withDefaultOnError } from '@/utils/defaults'; | ||||
| import type { UseValidationRule } from '@/composable/validation'; | ||||
| 
 | ||||
| const defaultValue = '{"a":{"_attributes":{"x":"1.234","y":"It\'s"}}}'; | ||||
| function transformer(value: string) { | ||||
|   return withDefaultOnError(() => { | ||||
|     return convert.js2xml(JSON5.parse(value), { compact: true }); | ||||
|   }, ''); | ||||
| } | ||||
| 
 | ||||
| const rules: UseValidationRule<string>[] = [ | ||||
|   { | ||||
|     validator: (v: string) => v === '' || JSON5.parse(v), | ||||
|     message: 'Provided JSON is not valid.', | ||||
|   }, | ||||
| ]; | ||||
| </script> | ||||
| 
 | ||||
| <template> | ||||
|   <format-transformer | ||||
|     input-label="Your JSON content" | ||||
|     :input-default="defaultValue" | ||||
|     input-placeholder="Paste your JSON content here..." | ||||
|     output-label="Converted XML" | ||||
|     output-language="xml" | ||||
|     :transformer="transformer" | ||||
|     :input-validation-rules="rules" | ||||
|   /> | ||||
| </template> | ||||
							
								
								
									
										12
									
								
								src/tools/xml-to-json/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/tools/xml-to-json/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| import { Braces } from '@vicons/tabler'; | ||||
| import { defineTool } from '../tool'; | ||||
| 
 | ||||
| export const tool = defineTool({ | ||||
|   name: 'XML to JSON', | ||||
|   path: '/xml-to-json', | ||||
|   description: 'Convert XML to JSON', | ||||
|   keywords: ['xml', 'json'], | ||||
|   component: () => import('./xml-to-json.vue'), | ||||
|   icon: Braces, | ||||
|   createdAt: new Date('2024-08-09'), | ||||
| }); | ||||
							
								
								
									
										32
									
								
								src/tools/xml-to-json/xml-to-json.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/tools/xml-to-json/xml-to-json.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
| <script setup lang="ts"> | ||||
| import convert from 'xml-js'; | ||||
| import { isValidXML } from '../xml-formatter/xml-formatter.service'; | ||||
| import { withDefaultOnError } from '@/utils/defaults'; | ||||
| import type { UseValidationRule } from '@/composable/validation'; | ||||
| 
 | ||||
| const defaultValue = '<a x="1.234" y="It\'s"/>'; | ||||
| function transformer(value: string) { | ||||
|   return withDefaultOnError(() => { | ||||
|     return JSON.stringify(convert.xml2js(value, { compact: true }), null, 2); | ||||
|   }, ''); | ||||
| } | ||||
| 
 | ||||
| const rules: UseValidationRule<string>[] = [ | ||||
|   { | ||||
|     validator: isValidXML, | ||||
|     message: 'Provided XML is not valid.', | ||||
|   }, | ||||
| ]; | ||||
| </script> | ||||
| 
 | ||||
| <template> | ||||
|   <format-transformer | ||||
|     input-label="Your XML content" | ||||
|     :input-default="defaultValue" | ||||
|     input-placeholder="Paste your XML content here..." | ||||
|     output-label="Converted JSON" | ||||
|     output-language="json" | ||||
|     :transformer="transformer" | ||||
|     :input-validation-rules="rules" | ||||
|   /> | ||||
| </template> | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user