i'd convert json data data frame in r. here i've done far:
library("rjson") result <- fromjson(file ="mypath/data.json") json_data_frame <- as.data.frame(result)
however, comes error this:
error in data.frame(company_id = "12345678", country_name = "china", : arguments imply differing number of rows: 1, 2, 0
i tried following code:
library("rjson") result <- fromjson(file ="mypath/data.json") final_data <- do.call(rbind, result)
and error comes up:
warning message: in (function (..., deparse.level = 1) : number of columns of result not multiple of vector length (arg 3)
i don't know going on here , how can solve it. appreciate if on this.
here pieces of json data:
{"business_id": "1234567", "country_name": "china", "hours": {"monday": {"close": "02:00", "open": "11:00"}, "tuesday": {"close": "02:00", "open": "11:00"}, "friday": {"close": "02:00", "open": "11:00"}, "wednesday": {"close": "02:00", "open": "11:00"}, "thursday": {"close": "02:00", "open": "11:00"}, "sunday": {"close": "02:00", "open": "12:00"}, "saturday": {"close": "02:00", "open": "12:00"}}, "open": true, "categories": ["bars", "nightlife", "restaurants"], "city": "beijing", "review_count": 5, "name": "chen's bar", "neighborhoods": ["west end"], "attributes": {"take-out": true, "wi-fi": "free", "good for": {"dessert": false, "latenight": false, "lunch": false, "dinner": false, "breakfast": false, "brunch": false}, "good dancing": false, "noise level": "loud", "takes reservations": false, "delivery": false, "ambience": {"romantic": false, "intimate": false, "classy": false, "hipster": false, "divey": false, "touristy": false, "trendy": false, "upscale": false, "casual": false}, "happy hour": true, "parking": {"garage": false, "street": false, "validated": false, "lot": false, "valet": false}, "has tv": true, "outdoor seating": false, "attire": "casual", "alcohol": "full_bar", "waiter service": true, "accepts credit cards": true, "good kids": false, "good groups": true, "caters": true, "price range": 1}, "type": "business"}
try using jsonlite library. work me
fromjson(temp) %>% as.data.frame
if want list.
fromjson(temp)
Comments
Post a Comment