Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// NEVER do this — eval executes any code in the JSON const data = eval("(" + untrustedJson + ")"); // dangerous! // Always use JSON.parse const safe = JSON.parse(untrustedJson); // Sanitize after parsing function sanitizeUser(user) { return { id: Number(user.id), // Coerce to number name: String(user.name).slice(0, 100), // Limit length role: ["user", "admin"].includes(user.role) ? user.role : "user", }; }
Result
Open