'Output JSON columns in an R data frame to a file without encoding
I have a data frame in R that has some normal columns and one column that I have created using toJSON that pulled in all columns of a data frame into one json column by row using
sapply(split(json.column, seq(nrow(json.column))), toJSON, pretty=TRUE)
and then using cbind to put the columns back into my data frame by row.
Looking at this column in R looks beautiful without any encoding. When I output this file to load into a database, it adds a significant amount of seemingly arbitrary backslashes (more than just " and [ ]) and encoding, which I need removed in order to load into the database.
output I have:
columna columnb columnc
abc123 12345 [\n {\n \"ID\":\\"GEORGE\\",\\\"SEX\\\":\\\\\\\"Male\\\\\\",\\\\\"AGE\\\\":46,\"GEO\",\"USA\" \\n }\\n]\"\n }\n]"
.....
output I want:
columna columnb columnc
abc123 12345 {"ID":"GEORGE","SEX":"Male","AGE":46,"GEO","USA"}
.....
I've tried str_remove and gsub and even cat, but the output file column (columnc in my example) doesn't seem to stay json in the column when I morph it.
I've tried other means of making my json column and can't find another way...
two days later and no luck. Any help would be greatly appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
