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 whitespace add ചെയ്ത് humans-ന് readable ആക്കുന്നു; minifying whitespace remove ചെയ്ത് machines-ന് faster ആക്കുന്നു.
JSON formatting എങ്ങനെ പ്രവർത്തിക്കുന്നു?
ഇൻപുട്ട് ബ്രൗസറിൽ built-in JSON.parse, JSON.stringify ഉപയോഗിച്ച് process ചെയ്യുന്നു. ഉയർന്ന ഘട്ടങ്ങൾ:
- ഇൻപുട്ട് textarea-ൽ നിന്ന് വായിക്കുകയും leading, trailing whitespace strip ചെയ്യുകയും ചെയ്യുന്നു.
- ബ്രൗസർ
JSON.parseഉപയോഗിച്ച് parse ചെയ്യുന്നു. Valid JSON അല്ലെങ്കിൽ parserSyntaxErrorthrow ചെയ്യും, line, column ഉൾക്കൊണ്ട് catch ചെയ്ത് display ചെയ്യുന്നു. - Valid ആയാൽ parsed value
JSON.stringify(value, null, indent)ഉപയോഗിച്ച് re-emit ചെയ്യുന്നു,indentതിരഞ്ഞെടുത്ത spacing (2 spaces, 4 spaces, tab). - Minification-ന്:
JSON.stringify(value)indent argument ഇല്ലാതെ call ചെയ്ത് ഏറ്റവും ചുരുക്കിയ valid form produce ചെയ്യുന്നു. - Output readonly textarea-ൽ എഴുതുന്നു; status panel Valid JSON അല്ലെങ്കിൽ exact parse error report ചെയ്യുന്നു.
ഈ ടൂൾ ഉപയോഗിച്ച് JSON format ചെയ്യേണ്ടത് എന്തുകൊണ്ട്?
- സ്വകാര്യത: ഓരോ parse, format, minify pass-ഉം ബ്രൗസറിൽ. JSON server-ലേക്ക് ഒരിക്കലും എത്തുന്നില്ല.
- ഉടനടി validation: misplaced commas, unquoted keys, single quotes, trailing commas precise line, column hint ഉൾക്കൊണ്ട് report ചെയ്യുന്നു.
- Review-ready output: consistent indentation ഉൾക്കൊണ്ട് pretty-printed JSON clean code-review diffs, readable configuration files.
- Production-ready minification: insignificant whitespace strip ചെയ്ത് API payloads, manifest files, embedded fixtures ship ചെയ്യുന്നതിന് മുൻപ് shrink ചെയ്യുന്നു.
JSON formatting-ന്റെ സാധാരണ ഉപയോഗങ്ങൾ?
JSON read, write ചെയ്യൽ web development, tooling-ൽ ഉടനീളം കാണുന്നു:
- APIs debug ചെയ്യൽ:
curlഅല്ലെങ്കിൽ network panel-ൽ നിന്ന് raw response paste ചെയ്ത് shape confirm ചെയ്ത്, key typo കണ്ടെത്തി, missing closing brace spot ചെയ്യൽ. - Configs cleanup: hand-edited
package.json,tsconfig.json, CI manifests re-indent ചെയ്ത് review, linters pass ആക്കൽ. - Logs reading: compact
application/jsonlog lines re-format ചെയ്ത് ഓരോ field-ഉം line up ചെയ്ത്, ticket-ൽ paste ചെയ്യുന്നതിന് മുൻപ് minify ചെയ്യൽ.
JSON formatting ഉദാഹരണം?
{"id":42,"name":"Ada Lovelace","email":"ada@example.com","roles":["admin","engineer"]} paste ചെയ്ത് 2-space indent ഉൾക്കൊണ്ട് FORMAT അടിച്ചാൽ ഒൻപത് lines ആയി expand ആകുന്നു, ഓരോ object field-ഉം array entry-ഉം സ്വന്തം line-ൽ. ഫോർമാറ്റ് ചെയ്ത text MINIFY ആക്കിയാൽ byte-for-byte compact string ആകുന്നു.
ഈ JSON formatter Node.js, Deno, ബ്രൗസർ runtime ഉപയോഗിക്കുന്ന അതേ engine ഉപയോഗിച്ച് parse ചെയ്ത് code, configs, logs-ലേക്ക് നേരിട്ട് paste ചെയ്യാൻ output emit ചെയ്യുന്നു.