JSON

JSON.parse and JSON.stringify.

JSON.stringify makes text. JSON.parse reads it back.

Goal

Round-trip a kiosk row.

const row = { city: "Nairobi", units: 12 };
const text = JSON.stringify(row);
console.log(text);
console.log(JSON.parse(text).units);
const rows = [
  { city: "Mombasa", units: 8 },
  { city: "Kisumu", units: 5 },
];
console.log(JSON.stringify(rows, null, 2));
const text = '{"city":"Nakuru","units":4}';
console.log(JSON.parse(text).city);
try {
  JSON.parse("not json");
} catch (err) {
  console.log("bad json");
}