## as_r()
as_r('[1, 2, 3]') # JSON integer array -> R integer vector
as_r('[1, 2.0, 3]') # JSON intger and double array -> R numeric vector
as_r('[1, 2.0, "3"]') # JSON mixed array -> R list
as_r('[1, 2147483648]') # JSON integer > R integer max -> R numeric vector
json <- '{"b": 1, "a": ["c", "d"], "e": true, "f": [true], "g": {}}'
as_r(json) |> str() # parsing complex objects
identical( # JSON scalar and length 1 array identical in R
as_r('{"a": 1}'), as_r('{"a": [1]}')
)
Run the code above in your browser using DataLab