April 2025 posted on 04.24.2025 Home Papers Essays Blog Verse Fiction JSON.stringify replacer parameter JSON.stringify has an optional second parameter replacer that can recursively transform properties during the stringify process. The replacer parameter can be a function or an array: JSON.stringify({ name: 'Peter', til: true }, ['name']); // '{"name":"Peter"}' function replacer(key, value) { if (key === 'name') { return 'Mekhaeil'; } return value; } JSON.stringify({ name: 'Peter', til: true }, replacer); // '{"name":"Mekhaeil","til":true}' No reactions yet
JSON.stringify replacer parameter
JSON.stringifyhas an optional second parameter replacer that can recursively transform properties during the stringify process.The
replacerparameter can be a function or an array: