Friday, January 20, 2023

Read Write File JSON Pada Programming-R

 


JSON singkatan dari Notasi Objek JavaScript. File JSON berisi data sebagai teks dalam format yang dapat dibaca manusia. Seperti file lainnya. Bahasa R menyediakan paket bernama rjson, yang harus diinstal dengan bantuan perintah install.packages yang sudah dikenal.

1. Install packages

Format : install.packages("rjson")



Contoh :


2. Membuat file JSON :employee.json 

{   

   "id":["1","2","3","4","5","6","7","8" ],  

   "name":["Shubham","Nishka","Gunjan","Sumit","Arpita","Vaishali","Anisha","Ginni" ],  

   "salary":["623","552","669","825","762","882","783","964"],  

   "start_date":[ "1/1/2012","9/15/2013","11/23/2013","5/11/2014","3/27/2015","5/21/2013",  

      "7/30/2013","6/17/2014"],  

   "dept":[ "IT","Operations","Finance","HR","Finance","IT","Operations","Finance"]  


3. Read file JSON

# Loading the package which is required to read JSON files.  

library("rjson")  

# Giving the input file name to the function fromJSON.  

result <- fromJSON(file = "employee.json")  

# Printing the result.  

print(result) 



3. Write file JSON

# Loading the package which is required to read JSON files.  

library("rjson")  

# Giving the input file name to the function fromJSON.  

result <- fromJSON(file = "employee.json")  

# Converting the JSON record to a data frame.  

data_frame <- as.data.frame(result)  

#Printing JSON data frame  

print(data_frame):


Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...