Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
How to Read Zip Files into R
Next article icon

How to read JSON files in R

Last Updated : 29 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy to read for humans as well as machines to parse and generate. It's widely used for APIs, web services and data storage. A JSON structure looks like this:

{
"name": "John",
"age": 30,
"city": "New York"
}

JSON data can be organized in objects (key-value pairs) and arrays (ordered lists of values) making it flexible for various use cases. Reading and writing JSON in R allows you to easily integrate it with web APIs, process data from external sources or handle configuration files.

To read JSON data in R we’ll use the jsonlite package which provides simple functions for parsing JSON into R objects.

1. Installing and Loading jsonlite Package

To work with json files we must install the jsonlite package available in R.

R
install.packages("jsonlite") 

Once installed, load the package:

R
library(jsonlite) 

2. Read JSON Data from a File

To read a JSON file on our system we will use the fromJSON() function. This function parses the JSON file and returns a corresponding R object such as a list or data frame depending on the structure of the JSON data. We will be using the following JSON file for this article.

R
json_data <- fromJSON("/content/indian_addresses_sample_data.json") 

3. Inspecting Data

We will use the str() function to display the structure of the data.

R
str(json_data) 

Output:

o1
Inspecting Data

4. Accessing Data in JSON

After loading the JSON data we can access specific elements like we do in a data frame.

R
city <- json_data$address$city print(city) 

Output:

o2
City from the address

Here in the JSON data is more complex such as containing nested objects or arrays so we accessed them using additional indexing of city.

5. Converting JSON Data to a Data Frame

If the JSON data is structured in a tabular format we can convert it linto a dataframe using as.data.frame() function.

R
df <- as.data.frame(json_data) 

Output:

o3
Converting JSON to Data Frame

With these methods we can easily work with JSON data in R and integrate it in our analysis workflow.


Next Article
How to Read Zip Files into R

P

priyanshugupta627
Improve
Article Tags :
  • R Language
  • R-JSON

Similar Reads

  • How to Read Large JSON file in R
    First, it is important to understand that JSON (JavaScript Object Notation), is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. JSON files are often used for data transmission between a server and a web application and can
    6 min read
  • How to Read Zip Files into R
    In the R Programming Language Zip files are compressed archives that store one or more files or directories in compressed format. They are commonly used to package and distribute files, particularly when working with huge datasets or many files. Zip files not only conserve disc space but also facili
    4 min read
  • How to Read XML File in R?
    XML (Extensible Markup Language) can be a widely used format for storing and transporting data. It can be structured and allowing the both humans and machines to easily parse and interpret the data it contains. In R programming, reading and processing XML files is straightforward thanks to the vario
    5 min read
  • How to read/write JSON File?
    Ruby is a dynamic, object-oriented programming language developed by Yukihiro Matsumoto in the mid-1990s. Its key features include a simple and elegant syntax, dynamic typing, object-oriented nature, support for mixins and modules, blocks and closures, metaprogramming, and a vibrant community with a
    6 min read
  • How to Read Many Files in R with Loop?
    When working with data in R Programming Language you often need to read multiple files into your environment. If you have a large number of files, doing this manually is impractical. Instead, you can use a loop to automate the process. This guide will show you how to read many files in R using a loo
    4 min read
  • How to read excel file in R ?
    We may work with structured data from spreadsheets, take advantage of R's capabilities for data analysis and manipulation, and incorporate Excel data into other R processes and packages by reading Excel files in R. The readxl package offers a simple and effective method for reading Excel files into
    3 min read
  • How to Read Many ASCII Files into R?
    Reading data from ASCII files into R is a common task in data analysis and statistical computing. ASCII files, known for their simplicity and wide compatibility, often contain text data that can be easily processed in R. Here we read multiple ASCII files into R Programming Language. What are ASCII F
    4 min read
  • How to parse a JSON File in PHP?
    We will explore how to parse a JSON file and display its data using PHP. PHP is a server-side scripting language commonly used to process and manipulate data. JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for both humans and machines to read and write. It st
    3 min read
  • How to Open JSON File?
    JSON (JavaScript Object Notation) is a lightweight, text-based data format that stores and exchanges data. Let's see how we can create and open a JSON file. How to Create JSON Files?Before learning how to open a JSON file, it's important to know how to create one. Below are the basic steps to create
    2 min read
  • How to Read JSON Files with Pandas?
    JSON (JavaScript Object Notation) store data using key-value pairs. Reading JSON files using Pandas is simple and helpful when you're working with data in .json format. There are mainly three methods to read Json file using Pandas Some of them are: Using pd.read_json() MethodUsing JSON Module and pd
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences