I'm a beginner to R.
I have a csv file:
key1 key2 key3 key4 key5 key6
value value value value value
value value value value value
value value value value value
etc.
I would to convert the CSV file into this format and save it in a .txt file so I can use it in a bulk upload for a server that requires this format:
{"key1": "value", "key2": "value", "key3": "value", "key4": "value", "key5": "value"}
{"key1": "value", "key2": "value", "key3": "value", "key4": "value", "key5": "value"}
{"key1": "value", "key2": "value", "key3": "value", "key4": "value", "key5": "value"}
Here is what I have so far in Rstudio:
#install packages
install.packages('jsonlite')
#libraries
library(readr)
library(jsonlite)
#import data
plantasia_menu_items <- read_csv("plantasia - menu_items.csv")
#View(plantasia_menu_items)
#to Json format
inJSON <- toJSON(plantasia_menu_items)
table <- fromJSON(inJSON)
print(inJSON)
This yields the data in the following format, but I don't know how to restructure it once I have it in JSON and then save it:
{"key1": "value", "key2": "value", "key3": "value", "key4": "value", "key5": "value"} {"key1": "value", "key2": "value", "key3": "value", "key4": "value", "key5": "value"} {"key1": "value", "key2": "value", "key3": "value", "key4": "value", "key5": "value"}
It must be on a new line for the server to understand the bulk upload and create a new entry. Stuck for a while now. Any ideas on how to restructure this into a matrix?