TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
JavaScript / Chapter 15 of 60~12 min • Beginner
Chapter 15JavaScript

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

  1. Define a JSON string
  2. Parse it
  3. Serialize the object

Example

JavaScript
const raw = '{"name":"QA","active":true}';
const data = JSON.parse(raw);
console.log(data.name);
console.log(JSON.stringify(data, null, 2));
Expected result: QA followed by formatted JSON
💡 Point to remember
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