Session Ready
Exercise

Manipulating parsed JSON

As you saw in the video, the output from parsing JSON is a list. One way to extract relevant data from that list is to use a package specifically designed for manipulating lists, rlist.

rlist provides two particularly useful functions for selecting and combining elements from a list: list.select() and list.stack(). list.select() extracts sub-elements by name from each element in a list. For example using the parsed movies data from the video (movies_list), we might ask for the title and year elements from each element:

list.select(movies_list, title, year)

The result is still a list, that is where list.stack() comes in. It will stack the elements of a list into a data frame.

list.stack(
    list.select(movies_list, title, year)
)

In this exercise you'll use these rlist functions to create a data frame with the user and timestamp for each revision.

Instructions
100 XP
  • First, you'll need to figure out where the revisions are. Examine the output from the str() call. Can you see where the list of 5 revisions is?
  • Store the revisions in revs.
  • Use list.select() to pull out the user and timestamp elements from each revision, store in user_time.
  • Print user_time to verify it's a list with one element for each revision.
  • Use list.stack() to stack the lists into a data frame.