mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-20 14:39:34 +02:00
Feature: Added Json Validation #issue42
This commit is contained in:
@@ -15,7 +15,8 @@ import { ToolComponentProps } from '@tools/defineTool';
|
|||||||
const exampleCards: CardExampleType<{}>[] = [
|
const exampleCards: CardExampleType<{}>[] = [
|
||||||
{
|
{
|
||||||
title: 'Valid JSON Object',
|
title: 'Valid JSON Object',
|
||||||
description: 'This example shows a correctly formatted JSON object.',
|
description:
|
||||||
|
'This example shows a correctly formatted JSON object. All property names and string values are enclosed in double quotes, and the overall structure is properly balanced with opening and closing braces.',
|
||||||
sampleText: `{
|
sampleText: `{
|
||||||
"name": "John",
|
"name": "John",
|
||||||
"age": 30,
|
"age": 30,
|
||||||
@@ -27,19 +28,19 @@ const exampleCards: CardExampleType<{}>[] = [
|
|||||||
{
|
{
|
||||||
title: 'Invalid JSON Missing Quotes',
|
title: 'Invalid JSON Missing Quotes',
|
||||||
description:
|
description:
|
||||||
'This example shows an invalid JSON structure where property names are missing quotes.',
|
'This example demonstrates an invalid JSON object where the property names are not enclosed in double quotes. According to the JSON standard, property names must always be enclosed in double quotes. Omitting the quotes will result in a syntax error.',
|
||||||
sampleText: `{
|
sampleText: `{
|
||||||
name: "John",
|
name: "John",
|
||||||
age: 30,
|
age: 30,
|
||||||
city: "New York"
|
city: "New York"
|
||||||
}`,
|
}`,
|
||||||
sampleResult: "❌ Error: Expected property name or '}' in JSON ",
|
sampleResult: "❌ Error: Expected property name or '}' in JSON",
|
||||||
sampleOptions: {}
|
sampleOptions: {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Invalid JSON with Trailing Comma',
|
title: 'Invalid JSON with Trailing Comma',
|
||||||
description:
|
description:
|
||||||
'This example shows an invalid JSON with a trailing comma at the end of the object.',
|
'This example shows an invalid JSON object with a trailing comma after the last key-value pair. In JSON, trailing commas are not allowed because they create ambiguity when parsing the data structure.',
|
||||||
sampleText: `{
|
sampleText: `{
|
||||||
"name": "John",
|
"name": "John",
|
||||||
"age": 30,
|
"age": 30,
|
||||||
@@ -63,6 +64,7 @@ export default function ValidateJson({ title }: ToolComponentProps) {
|
|||||||
|
|
||||||
const compute = (input: string) => {
|
const compute = (input: string) => {
|
||||||
const { valid, error } = validateJson(input);
|
const { valid, error } = validateJson(input);
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
setResult('✅ Valid JSON');
|
setResult('✅ Valid JSON');
|
||||||
} else {
|
} else {
|
||||||
@@ -81,7 +83,16 @@ export default function ValidateJson({ title }: ToolComponentProps) {
|
|||||||
|
|
||||||
<ToolInfo
|
<ToolInfo
|
||||||
title="What is JSON Validation?"
|
title="What is JSON Validation?"
|
||||||
description="JSON validation checks the syntax and structure of a JSON file to ensure it follows proper JSON format."
|
description="
|
||||||
|
JSON (JavaScript Object Notation) is a lightweight data-interchange format.
|
||||||
|
JSON validation ensures that the structure of the data conforms to the JSON standard.
|
||||||
|
A valid JSON object must have:
|
||||||
|
- Property names enclosed in double quotes.
|
||||||
|
- Properly balanced curly braces `{}`.
|
||||||
|
- No trailing commas after the last key-value pair.
|
||||||
|
- Proper nesting of objects and arrays.
|
||||||
|
This tool checks the input JSON and provides feedback to help identify and fix common errors.
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Separator backgroundColor="#5581b5" margin="50px" />
|
<Separator backgroundColor="#5581b5" margin="50px" />
|
||||||
|
Reference in New Issue
Block a user