-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(new tool): JSON <> XML #1231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
31e280c
feat(new tool): JSON <> XML
sharevb dadd8fd
Update src/tools/xml-to-json/index.ts
CorentinTh bbcb36a
Update src/tools/json-to-xml/index.ts
CorentinTh 3eaadde
Update src/tools/json-to-xml/index.ts
CorentinTh 489b3a6
Update src/tools/xml-to-json/index.ts
CorentinTh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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-06-30'), | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.