I have some data that is in almost-JSON format, but not quite. I'm trying to convert it from JSON using jsonlite
in R. Here is a sample of data:
field
{'email': {'name': 'Bob Smith', 'address': 'bob_smith@blah.com'}}
{'email': {'name': "Sally O'Mally", 'address': 'sally_omally@blah.com'}}
{'email': {'name': 'Sam Daniels', 'address': '"some text"<sam_daniels@xyz.com>'}}
{'email': {'name': "Johnson', Alan", 'address': 'alan.johnson@abc.com'}}
What I want to do is strip out all of the quotation marks (both single and double) that are inside of the main quotations. The data would then look like this:
field
{'email': {'name': 'Bob Smith', 'address': 'bob_smith@blah.com'}}
{'email': {'name': "Sally OMally", 'address': 'sally_omally@blah.com'}}
{'email': {'name': 'Sam Daniels', 'address': 'some text<sam_daniels@xyz.com>'}}
{'email': {'name': "Johnson, Alan", 'address': 'alan.johnson@abc.com'}}
After that, I can handle converting the single quotes to double quotes using stringr
and convert from JSON.
Any suggestions?
This is the error I currently get when trying to convert the original data from JSON:
> json_test2 <-
+ json_test %>%
+ dplyr::mutate(
+ field2 = map(field, ~ fromJSON(.) %>% as.data.frame())
+ )
Error: lexical error: invalid char in json text.
{'email': {'name': 'Bob S
(right here) ------^