Reading the Order With JSON.parse()

Marta’s order starts as text copied from the shop platform, and her finished label must become text for the courier’s booking form. Your JavaScript port already knows how to choose the address and fill in defaults. Here you’ll read a shortened pasted order and print a separate label preview Marta can check before sending.

Read the Pasted Order

As a quick recap, JSON.parse(ORDER_TEXT) reads JSON text, as Python’s json.loads(ORDER_TEXT) does, and returns JavaScript values. Here’s a shortened paste from order 1042, held in backticks so the string can span lines:

Language: JavaScript
const ORDER_TEXT = `{
  "id": 1042,
  "shipping_address": null,
  "insured_value": 0
}`;

const order = JSON.parse(ORDER_TEXT);
console.log(order.id);
console.log(order.shipping_address);
console.log(order.insured_value);

The sample prints:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.