Codington
0 of 6 problems solved • 0%

Exercise prompt

Read a Playlist

Use import json and json.loads(text) to decode a JSON string. Then access its fields like those of any other dictionary.

Example

Decoding preserves the shape of the data. A field can hold a list of separate objects.

import json parcel = json.loads('{"boxes":[{"weight":3},{"weight":7}]}') print(len(parcel["boxes"])) # 2 print(parcel["boxes"][1]["weight"]) # 7

Access one inner record first. To retrieve a field from every record, iterate over the list.

Your task

Implement track_titles(text). The JSON object contains a tracks list of objects with a title string. Return the titles in their original order, including duplicates.

track_titles('{"tracks": [{"title": "North"}, {"title": "South"}]}') # ["North", "South"]