I would like to create a JSON string of dataframe columns for each row of a dataframe (ie. to get a vector of Json strings). i.e. I would like to replicate this output from this code, but with more efficient code (as speed is atrocious on my non-toy dataframe):
apply(mtcars, 1, function(x) jsonlite::toJSON(as.list(x), na = "null", auto_unbox = TRUE))
Running the following is fast, however I'm not sure how to manipulate to get the same format as from the above code.
jsonlite::toJSON(mtcars, dataframe = "rows", pretty=FALSE, na = "null", auto_unbox = TRUE, na = "null")
Sample desired output:
Mazda RX4 "{"mpg":21,"cyl":6,"disp":160,"hp":110,"drat":3.9,"wt":2.62,"qsec":16.46,"vs":0,"am":1,"gear":4,"carb":4}" > Mazda RX4 Wag
"{"mpg":21,"cyl":6,"disp":160,"hp":110,"drat":3.9,"wt":2.875,"qsec":17.02,"vs":0,"am":1,"gear":4,"carb":4}"Datsun 710
"{"mpg":22.8,"cyl":4,"disp":108,"hp":93,"drat":3.85,"wt":2.32,"qsec":18.61,"vs":1,"am":1,"gear":4,"carb":1}"