JSON formatting म्हणजे काय?
JSON (JavaScript Object Notation) हे RFC 8259 आणि ECMA-404 ने परिभाषित एक lightweight, text-based data-interchange format आहे. JSON document सहा value types चे tree आहे — object, array, string, number, boolean आणि null. Formatting मानव ते tree वाचण्यासाठी whitespace जोडते; minifying machines ते wire वर जलद move करण्यासाठी whitespace काढते.
JSON formatting कसे कार्य करते?
तुमचे इनपुट built-in JSON.parse आणि JSON.stringify functions वापरून पूर्णपणे तुमच्या ब्राउझरमध्ये process होते. उच्च-स्तरीय steps:
- तुमचे इनपुट textarea मधून वाचले जाते आणि leading आणि trailing whitespace काढले जाते.
- Browser ते
JSON.parseने parse करतो. इनपुट valid JSON नसल्यास, parserSyntaxErrorthrow करतो जे caught होते आणि ज्या line आणि column वर थांबले त्यासह surface होते. - इनपुट valid असताना, parsed value
JSON.stringify(value, null, indent)ने re-emit होते, जिथेindentतुम्ही निवडलेले spacing आहे (2 spaces, 4 spaces किंवा tab character). - Minification साठी,
JSON.stringify(value)indent argument शिवाय called होते, त्याच value चे insignificant whitespace शिवाय shortest valid form produce करते. - आउटपुट readonly textarea ला लिहिले जाते, आणि status panel एकतर Valid JSON किंवा exact parse error report करतो जेणेकरून तुम्ही source fix करू शकता.
या साधनाने JSON का format करावे?
- गोपनीयता: प्रत्येक parse, format आणि minify pass तुमच्या browser मध्ये होतो. JSON कधीही आमच्या servers ला पोहोचत नाही.
- त्वरित validation: misplaced commas, unquoted keys, single quotes आणि trailing commas precise line आणि column hint सह reported होतात जेणेकरून तुम्ही थेट bug कडे जाऊ शकता.
- Review-ready आउटपुट: consistent indentation सह pretty-printed JSON स्वच्छ code-review diffs आणि readable configuration files produce करते.
- Production-ready minification: insignificant whitespace strip केल्याने API payloads, manifest files आणि embedded fixtures ship करण्यापूर्वी संकुचित होतात.
JSON formatting चे सामान्य उपयोग काय आहेत?
JSON वाचणे आणि लिहिणे वेब डेव्हलपमेंट आणि tooling मध्ये दिसते:
- Debugging APIs: shape confirm करण्यासाठी, key मध्ये typo शोधण्यासाठी, किंवा missing closing brace spot करण्यासाठी
curlकिंवा network panel मधून raw response पेस्ट करणे. - Configs cleanup करणे: ते review आणि linters pass करण्यासाठी हातांनी edited
package.json,tsconfig.jsonकिंवा CI manifests re-indent करणे. - Logs वाचणे: compact
application/jsonlog lines re-formatting करणे जेणेकरून प्रत्येक field पुढील खाली line up होईल, नंतर ticket मध्ये पेस्ट करण्यापूर्वी पुन्हा minify करणे.
JSON formatting उदाहरण कसे दिसते?
{"id":42,"name":"Ada Lovelace","email":"ada@example.com","roles":["admin","engineer"]} पेस्ट करणे आणि 2-space indent सह FORMAT दाबणे ते नऊ ओळींमध्ये expand करते, प्रत्येक object field आणि प्रत्येक array entry स्वतःच्या ओळीवर. Formatted text वर MINIFY दाबल्याने ते पुन्हा त्याच compact string ला, byte for byte, collapse होते.
हा JSON formatter तुमचा Node.js, Deno किंवा browser runtime वापरतो त्याच engine ने parse करतो आणि आउटपुट emit करतो जे तुम्ही थेट code, configs किंवा logs मध्ये पेस्ट करू शकता.