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>Parsing and Restoring Custom Class Instances</h2> <p>Click below to parse JSON that represents a <code>Point</code> object and restore it as an actual class instance using a <code>reviver</code> function.</p> <button onclick="loadPoint()">Parse Point</button> <div class="user-card" id="pointCard"> <h3>Point Instance</h3> <p><strong>X:</strong> <span id="xValue"></span></p> <p><strong>Y:</strong> <span id="yValue"></span></p> <p><strong>Is Point Instance:</strong> <span id="isInstance"></span></p> </div> <script> class Point { constructor(x, y) { this.x = x; this.y = y; } } function loadPoint() { const json = '{"__type":"Point","x":10,"y":20}'; const point = JSON.parse(json, (key, value) => { if (value && value.__type === "Point") { return new Point(value.x, value.y); } return value; }); document.getElementById('xValue').textContent = point.x; document.getElementById('yValue').textContent = point.y; document.getElementById('isInstance').textContent = point instanceof Point ? 'Yes' : 'No'; document.getElementById('pointCard').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