I am trying to parse out some JSON data that is currently in a single column of a .csv file and make that output another .csv file. I have been trying to follow along with what the other threads have said but I'm not having any luck. So, my problem is the following: I have a .csv file that has lots of variables, a few of which are in JSON format. My question is, how do I parse one of these variables out to make a .csv file of just that variable? My data looks like this (this is just one line of it, I have about 150,000 rows of this):
Then the next cell (foo$JSON_var[2]) has the same format but with different values, etc. I'm looking to break this up into a .csv file that has variable names: position, name, var_c, var_r, var_b, var_v, var_p, and var_pp. (again, I need this for the whole data set, not just the single cell I gave as the example).
I tried using
but got error "STRING_ELT() can only be applied to a 'character vector', not a 'integer'"
I also tried (based on what I have read on other threads)
But I got "Error in readLines(foo$JSON_var) :
'con' is not a connection"
Any help with trying to figure out how to parse out these data into a usable form would be highly appreciated. Thanks for looking.
**Edited to fix the assignment tag in the first code snippet**
Code:
foo$JSON_var[1] <-
[{u'position': 0, u'name': u'player1', u'var_c': 400, u'var_r': 0, u'var_b': 0, u'var_v': 10, u'var_p': 0, u'var_pp': 0},
{u'position': 1, u'name': u'player2', u'var_c': 280, u'var_r': 0, u'var_b': 0, u'var_v': 20, u'var_p': 0, u'var_ppf': 0},
{u'position': 2, u'name': u'player3', u'var_c': 196, u'var_r': 0, u'var_b': 0, u'var_v': 30, u'var_p': 0, u'var_pp': 0},
{u'position': 3, u'name': u'player4', u'var_c': 0, u'var_r': 0, u'var_b': 0, u'var_v': 40, u'var_p': 0, u'var_pp': 0}]
I tried using
Code:
json_data <- fromJSON(foo$JSON_var)
I also tried (based on what I have read on other threads)
Code:
json_data <- fromJSON(paste(readLines(foo$JSON_var), collapse=""))
'con' is not a connection"
Any help with trying to figure out how to parse out these data into a usable form would be highly appreciated. Thanks for looking.
**Edited to fix the assignment tag in the first code snippet**
Last edited: