it-tools/src/tools/json-minify/json-minify.vue
Marvin 9526ed8324
fix(typos): fixed more typos & uppercase JSON (#475)
* fix(About): typo

* uppercase json & typos
2023-06-23 15:23:47 +02:00

27 lines
831 B
Vue

<script setup lang="ts">
import JSON5 from 'json5';
import type { UseValidationRule } from '@/composable/validation';
import { withDefaultOnError } from '@/utils/defaults';
const defaultValue = '{\n\t"hello": [\n\t\t"world"\n\t]\n}';
const transformer = (value: string) => withDefaultOnError(() => JSON.stringify(JSON5.parse(value), null, 0), '');
const rules: UseValidationRule<string>[] = [
{
validator: (v: string) => v === '' || JSON5.parse(v),
message: 'Provided JSON is not valid.',
},
];
</script>
<template>
<format-transformer
input-label="Your raw JSON"
:input-default="defaultValue"
input-placeholder="Paste your raw JSON here..."
output-label="Minified version of your JSON"
output-language="json"
:input-validation-rules="rules"
:transformer="transformer"
/>
</template>