Data Science Training in Mumbai : – Reading JSON files using R Programming in Visual Studio.

1

JSON files stores data as text in human-readable format similar to XML.

JSON Stands for Javascript object Notation which is commonly used in Web development to pass data.

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.

2

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.

3

Now in the feature installation window check and install the following features.

For Visual Studio 2017

Contains Tools for Data Science

4



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

https://docs.microsoft.com/en-us/visualstudio/rtvs/installing-r-tools-for-visual-studio

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:

https://ftp.iitm.ac.in/cran/

5



Type the following command in Visual Studio or R Interactive:

install.packages(“rjson”)

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

6

This is our project structure:

7







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.

{

“ID”:[“1″,”2″,”3″,”4″,”5″,”6″,”7″,”8” ],
“Name”:[“vv”,”ww”,”mm”,”rr”,”Gary”,”Nina”,”Simon”,”Guru” ],
“Salary”:[“623.3″,”515.2″,”611″,”729″,”843.25″,”578″,”632.8″,”722.5” ],

  “StartDate”:[

“1/1/2012″,”9/23/2013″,”11/15/2014″,”5/11/2014″,”3/27/2015″,”5/21/2013”,
“7/30/2013″,”6/17/2014”],
“Dept”:[ “IT”,”Operations”,”IT”,”HR”,”Finance”,”IT”,”Operations”,”Finance”]
}

# Load the package required to read JSON files.
library(“rjson”)

# Give the input file name to the function.
result <- fromJSON(file = "D:\\RProgramme\\1.json")

# Print the result.
print(result)

Output:

8

# converting Json data to Data Frame
json_data_frame <- as.data.frame(result)
print(json_data_frame)

9









Syllabus of Data Science training in Mumbai

Comments

comments

This entry was posted in Class Room Training and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.