I'm processing data within Python, and would like to stream records to R using JSON formatting and simplejson
on the Python side, and rjson
on the R
side.
How can I output records out of Python so that R's fromJSON
can process them into a one-line dataframe? Thanks
try:
import simplejson as json
except ImportError:
import json
record = {'x':1,'y':1}
print json.dumps( record )
Result:
{"y": 1, "x": 1}
However, I'd need the result to be "{\"x\":1,\"y\":2}"
, as R
needs that formatting to use the data:
library(rjson)
as.data.frame( fromJSON( "{\"x\":1,\"y\":2}" ) )
x y
1 1 2
Thanks.