JSON.stringify का वह दूसरा पैरामीटर जिसे अक्सर अनदेखा किया जाता है
2025-04-01
सिर्फ JSON.stringify(obj) तक सीमित न रहें। replacer और space से आप output को सुरक्षित, छोटा या अधिक पठनीय बना सकते हैं।
replacer array = whitelist
['id','name'] देने पर केवल चुने गए keys output में आते हैं।
JSON.stringify(user, ["id", "name"]);replacer function
undefined लौटाकर field हटाएं; password redact और custom transformations करें।
JSON.stringify(obj, (k, v) => k === "password" ? undefined : v);space
तीसरा पैरामीटर 2 या '\t' देने से pretty-print मिलता है; बिना इसके compact JSON बनता है।
toJSON
ऑब्जेक्ट toJSON परिभाषित कर सकते हैं; Date default रूप से ISO string देता है।