library(tidyverse)
library(dplyr)
library(jsonlite)

Load data

url<- "https://raw.githubusercontent.com/stormwhale/data-mines/refs/heads/main/lab%207.csv"
df<- read.csv(url, row.names= NULL, header=TRUE, sep=',')
head(df)

To Json:

#convert to json format:
json_df<- toJSON(df, pretty=TRUE)
write(json_df, file='lab_7.json')

To HTML

library(knitr)

html_df<- kable(df, format = "html", table.attr = "class='dataframe'")

writeLines(html_df, "lab7.html")

To XML:

library(XML)
# Convert dataframe to XML
xml_data <- xmlTree("data")
## Warning in xmlRoot.XMLInternalDocument(currentNodes[[1]]): empty XML document
for (i in 1:nrow(df)) {
  xml_data$addNode("row", attrs = list(
    Category = df$Category[i], 
    Item.Name = df$Item.Name[i], 
    Item.ID = df$Item.ID[i]),
    Brand = df$Brand[i],
    Price = df$Price[i],
    Variation.ID = df$Variation.ID[i],
    Variation.Details = df$Variation.Details[i],
    Detail = df$Column1[i]
    )
}
saveXML(xml_data, file = "lab_7.xml")
## [1] "lab_7.xml"

parquet:

library(arrow)
## 
## Attaching package: 'arrow'
## The following object is masked from 'package:lubridate':
## 
##     duration
## The following object is masked from 'package:utils':
## 
##     timestamp
write_parquet(df, 'lab_7.parquet')