JSON क्या है और यह क्यों टूट जाता है?

JSON (JavaScript Object Notation) एक हल्का डेटा प्रारूप है जिसका उपयोग सिस्टम के बीच जानकारी को संग्रहीत और विनिमय करने के लिए किया जाता है। यह सख्त सिंटैक्स नियमों का पालन करता है: strings को double quotes का उपयोग करना चाहिए, objects को proper braces की आवश्यकता है, arrays को brackets की आवश्यकता है, और trailing commas निषिद्ध हैं। यहां तक कि एक भी गलत जगह पर रखा गया character पूरे document को invalid बना सकता है।

JSON आमतौर पर logs, chat messages, या code editors से copy करने पर टूट जाता है। Hand-editing अक्सर missing quotes, unescaped characters, या mismatched brackets जैसी त्रुटियों का परिचय देता है। APIs कभी-कभी malformed responses return करते हैं, और configuration files manual edits के दौरान corrupted हो जाती हैं।

Tool विवरण

यह JSON Repairer स्वचालित रूप से broken या malformed JSON documents को ठीक करता है। यह input का विश्लेषण करता है, syntax errors की पहचान करता है, और original data structure और values को संरक्षित करते हुए valid JSON का पुनर्निर्माण करता है। यह tool सामान्य समस्याओं को संभालता है जिनके लिए अन्यथा tedious manual correction की आवश्यकता होती।

उदाहरण

Keys के चारों ओर missing quotes:

{name: "John", age: 30}

Repaired:

{ "name": "John", "age": 30 }

Trailing commas:

{ "items": ["apple", "banana", "orange"] }

Repaired:

{ "items": ["apple", "banana", "orange"] }

Double quotes की जगह single quotes:

{'status': 'active', 'count': 5}

Repaired:

{ "status": "active", "count": 5 }

Unquoted string values:

{"message": Hello World}

Repaired:

{ "message": "Hello World" }

Missing closing brackets:

{"data": [1, 2, 3}

Repaired:

{ "data": [1, 2, 3] }

विशेषताएं

  • Keys और string values के चारों ओर स्वचालित रूप से missing quotes जोड़ता है
  • Arrays और objects से trailing commas को हटाता है
  • Single quotes को double quotes में परिवर्तित करता है
  • Mismatched या missing brackets और braces को repair करता है
  • Pretty-print या minified output के साथ optional formatting

यह कैसे काम करता है

Repair algorithm input को character by character parse करता है, एक valid JSON structure बनाता है। जब यह invalid syntax का सामना करता है, तो यह common JSON mistakes के आधार पर correction rules लागू करता है। Missing quotes को context से infer किया जाता है, unmatched brackets को appropriate positions पर close किया जाता है, और invalid characters को handle या escape किया जाता है। परिणाम syntactically correct JSON है जिसे किसी भी JSON parser द्वारा parse किया जा सकता है।

उपयोग के मामले

  • Debugging API responses: APIs या web services से return किए गए malformed JSON को processing से पहले ठीक करें
  • Cleaning log data: Application logs या console output से निकाले गए JSON fragments को repair करें
  • Fixing configuration files: Hand-edited JSON configs को ठीक करें जिनमें syntax errors जमा हो गई हैं

सीमाएं

  • पूरी तरह से unstructured text को repair नहीं कर सकता जिसका JSON से कोई संबंध नहीं है
  • Ambiguous input को intended से अलग तरीके से interpret कर सकता है (हमेशा output को verify करें)
  • Semantic errors (wrong data types, incorrect values) का पता नहीं लगाया जाता या ठीक नहीं किया जाता