ยง2024-12-15

JSON is a text-based data format following JavaScript object syntax, which was popularized by Douglas Crockford. Even though it closely resembles JavaScript object literal syntax, it can be used independently from JavaScript, and many programming environments feature the ability to read (parse) and generate JSON.

> library(jsonlite)
> # Create an R list
r_list <- list(name = "Alice", age = 30, city = "New York")
> r_list[2]
$age
[1] 30

> r_list$age
[1] 30
> # Convert to JSON format
json_data <- toJSON(r_list)
> json_data
{"name":["Alice"],"age":[30],"city":["New York"]} 
> r_list <- list(name = c("Alice", "Alexlai"), age = 30, city = "New York")
> json_data <- toJSON(r_list)
> json_data
{"name":["Alice","Alexlai"],"age":[30],"city":["New York"]}

json_data <- { "person": { "name": "John", "age": 30 }, "address": { "city": "New York", "zip": "10001" } }