0
0
R Programmingprogramming~10 mins

JSON with jsonlite in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert a list to JSON using jsonlite.

R Programming
library(jsonlite)
my_list <- list(name = "Alice", age = 25)
json_data <- toJSON([1])
print(json_data)
Drag options to blanks, or click blank then click option'
Ajson_data
Bmy_list
Clist
DtoJSON
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the result variable instead of the data variable.
Using the function name inside itself.
2fill in blank
medium

Complete the code to prettify JSON output with jsonlite.

R Programming
library(jsonlite)
my_list <- list(city = "Paris", population = 2148327)
json_data <- toJSON(my_list, [1] = TRUE)
cat(json_data)
Drag options to blanks, or click blank then click option'
Aauto_unbox
Bdigits
CsimplifyVector
Dpretty
Attempts:
3 left
💡 Hint
Common Mistakes
Using auto_unbox which controls single values, not formatting.
Confusing digits with formatting.
3fill in blank
hard

Fix the error in the code to parse JSON string back to R object.

R Programming
library(jsonlite)
json_str <- '{"fruit":"apple","count":10}'
my_data <- [1](json_str)
print(my_data)
Drag options to blanks, or click blank then click option'
AfromJSON
BparseJSON
CtoJSON
Djsonlite
Attempts:
3 left
💡 Hint
Common Mistakes
Using toJSON() which converts R to JSON, not the other way.
Using a non-existent function parseJSON().
4fill in blank
hard

Fill both blanks to create a JSON from a named vector and parse it back.

R Programming
library(jsonlite)
vec <- c(a = 1, b = 2, c = 3)
json_vec <- [1](vec, [2] = TRUE)
parsed_vec <- fromJSON(json_vec)
print(parsed_vec)
Drag options to blanks, or click blank then click option'
AtoJSON
Bpretty
Cauto_unbox
DfromJSON
Attempts:
3 left
💡 Hint
Common Mistakes
Using fromJSON in the first blank which is for parsing JSON.
Using auto_unbox instead of pretty for formatting.
5fill in blank
hard

Fill all three blanks to convert a data frame to JSON with unboxed values and parse it back.

R Programming
library(jsonlite)
df <- data.frame(name = c("Tom", "Sue"), age = c(30, 25))
json_df <- [1](df, [2] = TRUE)
parsed_df <- [3](json_df)
print(parsed_df)
Drag options to blanks, or click blank then click option'
AtoJSON
Bauto_unbox
CfromJSON
Dpretty
Attempts:
3 left
💡 Hint
Common Mistakes
Using pretty instead of auto_unbox for the second blank.
Using toJSON instead of fromJSON for parsing.