Chris
Chris

Reputation: 1475

Reading JSON from file into tidyjson

I'm trying to read json from the location below and create a tidy version using tidyjson.

https://raw.githubusercontent.com/mysociety/parlparse/master/members/people.json

The guides for tidyjson don't mention how to read the file. I've tried various ways including fromJSON, read_JSON, readJSON and read_lines but hit errors in each example.

e.g.

peopleJSON <- read_lines(url("https://raw.githubusercontent.com/mysociety/parlparse/master/members/people.json"))
people <- peopleJSON  %>% as.tbl_json

Error: parse error: premature EOF
                                       {
                     (right here) ------^

I'm not sure if I am doing something wrong or whether the issue is with the data.

Any help would be warmly welcomed.

Upvotes: 1

Views: 668

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388982

fromJSON from jsonlite returns a list of 4 dataframes.

data <- jsonlite::fromJSON('https://raw.githubusercontent.com/mysociety/parlparse/master/members/people.json')

sapply(data, dim)

#     memberships organizations persons posts
#[1,]       45674            43   13902  2370
#[2,]          15             4       5     8

You can access individual dataframes with data$memberships, data$organizations etc.

Upvotes: 2

Related Questions