0

I try to read online json data to R through the below codes in R:

library('jsonlite')

address<-'https://data.cityofchicago.org/resource/qnmj-8ku6.json'

sample<-fromJSON(address)

The codes did run and have results in right format of a table. But only produced 1000 observations while the original city portal database has more than 200,000 observations. I am not sure what to be fixed to download the whole dataset. Please help.

lnx
  • 45
  • 3
  • Are you sure? Go to the page `https://data.cityofchicago.org/resource/qnmj-8ku6.json`, scroll to the end and look at the `id` field (9909096). Then look at `tail(sample)` - `id` field (9909096) – SymbolixAU Jun 21 '16 at 22:11
  • What's the link to the "original city portal database" ? – SymbolixAU Jun 21 '16 at 22:12
  • the original website: https://data.cityofchicago.org/Public-Safety/Crimes-2014/qnmj-8ku6 – lnx Jun 22 '16 at 16:53

1 Answers1

0

You're using the wrong link to get the data. You can see the correct link by going to 'Export'

library(jsonlite)

address <- "https://data.cityofchicago.org/api/views/qnmj-8ku6/rows.json?accessType=DOWNLOAD"
sample <- fromJSON(address)

length(sample)
# [1]

length(sample[[2]])
# [1] 274228

Although, you may want to get it as a .csv to make it easier to work with straight away?

address <- "https://data.cityofchicago.org/api/views/qnmj-8ku6/rows.csv?accessType=DOWNLOAD"
sample_csv <- read.csv(address)

nrow(sample_csv) 
# [1] 274228

str(sample_csv) 
# 'data.frame': 274228 obs. of  22 variables:
#  $ ID                  : int  10512552 10517063 10517120 10518590 10518648 
# $ Case.Number         : Factor w/ 274219 levels "HA107183","HA156050",..
# $ Date                : Factor w/ 112977 levels "01/01/2014 01:00:00 AM",..
# $ Block               : Factor w/ 27499 levels "0000X E 100TH PL",..
# $ IUCR                : Factor w/ 331 levels "0110","0141",..
# $ Primary.Type        : Factor w/ 33 levels "ARSON","ASSAULT",..
# $ Description         : Factor w/ 310 levels "$500 AND UNDER",..
# ... etc
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139