Session Ready
Exercise

From JSON to R (2)

JSON is built on two structures: objects and arrays. To help you experiment with these, four JSON strings are included in the sample code. It's up to you to change them appropriately and then call jsonlite's fromJSON() function on them each time.

Instructions
100 XP
  • Change the assignment of json1 such that the R vector after conversion contains the numbers 1 up to 6, in ascending order. Next, call fromJSON() on json1.
  • Adapt the code for json2 such that it's converted to a named list with two elements: a, containing the numbers 1, 2 and 3 and b, containing the numbers 4, 5 and 6. Next, call fromJSON() on json2.
  • Remove characters from json3 to build a 2 by 2 matrix containing only 1, 2, 3 and 4. Call fromJSON() on json3 again.
  • Add characters to json4 such that the data frame in which the json is converted contains an additional observation in the last row. For this observations, a equals 5 and b equals 6. Call fromJSON() one last time, on json4.