I have trouble reading a CSV file I exported from a mysql database which contains a column with a JSON string. More concretely, I want to get access to all values in the JSON string. I created a simple example to visualize my problem:
This is my CSV file (test.csv):
"id","code","values"
1,"12b222a","{\"first\": 5, \"second\": 5}"
This is how I read it in R:
library(data.table)
library(jsonlite)
test_data<-fread("test.csv")
When I try
rd <- fromJSON(test_data[,"values"])
I reveive the following error message:
Error: Argument 'txt' must be a JSON string, URL or file.
The problem is that when I run
test_data[,"values"]
I receive the following content which contains double backslashes as escape characters:
values
1: {\\"first\\": 5, \\"second\\": 5}
How can I avoid having two backslashes that cause the trouble with fromJSON?