Codelab Editor
Free Online HTML Editor
Run
Learn JSON
<!DOCTYPE html> <html> <head> <style> body { padding: 10px; background: #fdfdfd; font-family: sans-serif; } .user-card { display: none; max-width: 320px; padding: 16px; border: 1px solid #ccc; border-radius: 12px; background-color: #f5f5f5; margin-top: 20px; } .user-card h3 { margin: 0 0 10px; font-size: 20px; } .user-card p { margin: 6px 0; } button { margin-right: 10px; padding: 8px 16px; border: none; background-color: #0088cc; color: white; border-radius: 6px; cursor: pointer; } button:hover { background-color: #006fa3; } </style> </head> <body> <h2>Transform JSON Values Using <code>reviver</code></h2> <p>Click below to parse and display employee details, with the <kbd>joined</kbd> date formatted during parsing.</p> <button onclick="loadEmployee()">Show Emma Profile</button> <div class="user-card" id="userCard"> <h3 id="fullName"></h3> <p><strong>Age:</strong> <span id="age"></span></p> <p><strong>Joined:</strong> <span id="joined"></span></p> </div> <script> function loadEmployee() { const json = '{"firstName":"Emma","lastName":"Davis","age":28,"joined":"2020-06-01"}'; const employee = JSON.parse(json, function(key, value) { if (key === 'joined') { const date = new Date(value); return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); } return value; }); document.getElementById('fullName').textContent = employee.firstName + ' ' + employee.lastName; document.getElementById('age').textContent = employee.age; document.getElementById('joined').textContent = employee.joined; document.getElementById('userCard').style.display = 'block'; } </script> </body> </html>
Editor Commands
Ctrl
F
Find
Ctrl
G
Find Next
Ctrl
⇧
G
Find Previous
Ctrl
⇧
F
Find & Replace
Ctrl
]
Indent Code Right
Ctrl
[
Indent Code Left
⇧
Tab
Auto Indent Code
Ctrl
/
Line Comment
Ctrl
Alt
/
Block Comment
TutsInsider Actions
Alt
S
Run Code
Ctrl
C
Copy Editor Code
Ctrl
A
Select All Editor Code
Ctrl
S
Save/Download
Ctrl
Alt
X
Rotate
Ctrl
Alt
T
Switch Theme
Ctrl
⇧
C
Open Console
Esc
Close Console