JSON files stores data as text in human-readable format similar to XML.
Several RESTful web services return data in JSON format and in some ways simpler and more efficient than XML.
In R programming we can read JSON files and convert them into other formats
It can be achieved by importing various library which are required to read JSON files these libraries are readily available in CRAN repository.
We can parse the JSON data after reading it in R to further analyse it.
To create and run our R program in Visual Studio we must first install some tools.
Now open Visual Studio on your pc and then click on Get Tools and features… inside Tools.
Now in the feature installation window check and install the following features.
For Visual Studio 2017
Contains Tools for Data Science
After this please install R tools from the following link if the above package is not installed properly from the following link
But it is not necessary
You can also install R programming tool go to the following link for better support and download the software and install it.
For Windows Users:
Type the following command in Visual Studio or R Interactive:
For Linux Users:
If you are on Linux platform then you can use this fast and easy command used in Linux which can be used to install R. The yum command is used for installing like this:
$ yum install R
For Ubuntu Linux or other Debian-related OSs, a more direct method is:
$ apt-get install r-base
Now let us start creating our R application in visual studio
Go to Files ->Project and add a new R project
This is our project structure:
Now on the top left side is a new R file (script.R) where we can edit source code with all of Visual Studio Ide editing features.
Also on the bottom left of Visual Studio is where you can find an R Interactive window in which you can interactively develop and test code.
We can directly use R Interactive without the need of opening any new project.
Before we can start coding it is required to create a JSON file in our desired location with .json extension and use the following dummy data in it.
# Load the package required to read JSON files.
# Give the input file name to the function.
result <- fromJSON(file = "D:\\RProgramme\\1.json")
# Print the result.
# converting Json data to Data Frame
json_data_frame <- as.data.frame(result)