JSON File in R

JSON file in R is stored as an R list. JSON stands for JavaScript Object Notation. The JSON file is consists of the data as text in a human-readable format.

Install rjson Package

You can install the R JSON package with the following command in the R console.

Input Data

Create a JSON file by copying the below data into a text editor like notepad. Save the file with a .json extension and choosing the file type as all files(*.*).

Read the JSON File

Reading a JSON file in R is quite a simple task. The JSON file in R is read using the fromJSON() function from rjson(). It is stored as an R list.

Output:

JSON File in R

Writing into a JSON file 

One need to create a JSON Object using toJSON() function before he writes the data to a JSON file.

Before creating a JSON file we need to create a JSON object using toJSON() function. To write data into a JSON file the write() function is used in R.

Output:

json1

Convert JSON to a Data Frame

We can convert the extracted data to an R data frame using the as.data.frame() function.