Chapter 15: JSON and test data
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
JSON and test data
JSON is a text format for data exchange. It uses double-quoted property names and strings, and does not allow functions or comments. JSON.parse converts valid JSON text to a JavaScript value; JSON.stringify converts supported values to text.
How it works
Step-by-step walkthrough
- Define a JSON string
- Parse it
- Serialize the object
Example
const raw = '{"name":"QA","active":true}';
const data = JSON.parse(raw);
console.log(data.name);
console.log(JSON.stringify(data, null, 2));Never assume external JSON has the structure your code expects.
✎ Your practice task
Add a numeric id to the JSON and parse again.
Knowledge check
Which method converts JSON text into a value?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.