forked from ujjwalkarn/DataScienceR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readJSON.R
39 lines (29 loc) · 875 Bytes
/
readJSON.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#READING JSON FILE USING R
# library(rjson)
# myfile <- 'C:\\Users\\ujjwal.karn\\Desktop\\Tweets\\python.json'
# document2 <- fromJSON(file = myfile)
#
# library(jsonlite)
# winners <- fromJSON(myfile)
# winners <- fromJSON(myfile, flatten=TRUE)
#
# document$text
#
# json_file <- stream_in(file(myfile))
#
#
# dat <- fromJSON(sprintf("[%s]", paste(readLines(myfile), collapse=",")))
#
# dat$text
library(jsonlite)
options(encoding = "UTF-8")
# read in individual JSON lines
json_file <- "C:\\Users\\ujjwal.karn\\Desktop\\Tweets\\python.json"
# turn it into a proper array by separating each object with a "," and
# wrapping that up in an array with "[]"'s.
dat <- fromJSON(sprintf("[%s]", paste(readLines(json_file), collapse=",")))
dim(dat)
## [1] 3959 18
tweets<-dat$text
tweets
#tweetsdf <- data.frame(matrix(unlist(dat$text), nrow=nrow(dat), byrow=T))