Most modern web browsers support native JSON encoding and decoding. Let's examine the methods available inside this object:
Method | Description |
JSON.stringify(object) | We use JSON.stringify to convert JavaScript objects to JSON-formatted text. |
JSON.parse(string) | We use JSON.parse to convert text into JavaScript objects. |
Let's learn how to encode and decode with the JSON notation by creating a simple model—a 3D line. Here, we will be focusing on how we do JSON encoding and decoding. Follow the given steps:
- In your browser, open the interactive JavaScript console. Use the following table for assistance:
Browser | Shortcut keys (PC/Mac) |
Firefox | Ctrl + Shift + K/Command + Alt + K |
Safari | Ctrl + Shift + C/Command + Alt + C |
Chrome | Ctrl + Shift + J/Command + Alt + J |
- Create a JSON object by typing the following...