Getting and cleaning data - JSON Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

JSON SALIENT FACTS

A

Javascript Object Notation

Lightweight data storage

Common format for data from application programming interfaces (APIs)

Similar structure to XML but different syntax/format

Data stored as

Numbers (double)

Strings (double quoted)

Boolean (true or false)

Array (ordered, comma separated enclosed in square brackets [])

Object (unorderd, comma separated collection of key:value pairs in curley brackets {})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

JSON PACKAGE & FIRST STEPS

A

install.packages(“jsonlite”)

library(jsonlite)

reading data into memory

jsonData <- fromJSON(“https://api.github.com/users/jtleek/repos”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

JSON EXPLORING DATA

A

Use loading variable as handle to refer to data in memory

Find 1st level headings:
> names(jsonData)

Drill to secon level by referring to a chosen heading using $
> names(jsonData$owner)

List content
> jsonData$owner$login

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

WRITING DATA FRAME TO JSON

A

Start with a DF assigned to the variable iris

Transform DF into a JSON format
> myjson <- toJSON(iris, pretty=TRUE)

Read the result
> cat(myjson)

Convert back from JSON
> iris2 <- fromJSON(myjson)

Display result
> head(iris2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

JSON RESOURCES

A

http://www.json.org/

A good tutorial on jsonlite :
http://www.r-bloggers.com/new-package-jsonlite-a-smarter-json-encoderdecoder/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly