In this recipe we will discuss how to write a JSON file through R
We use "rjson" package to write json files
We create a list of objects using vector() function
Syntax: vector(mode, length)
list_1 = vector(mode="list", length = 2) # assigning different objects to the list list_1[] = c("Rick","Dan","Michelle","Ryan") list_1[] = c("623.3","843.25","578","722.5")
First we read the above list to JSON. We use toJSON function to do so.
myfile = toJSON(list_1)
Writing the JSON object created to a file named "myJSON". We use write() function to do so.