fifa fails, guy kawasaki and real estate in sf - find out about all three by querying json

14
Working with data in JSON format Adrian Kalbarczyk | Ela Bednarek

Upload: ela-bednarek

Post on 30-Nov-2014

566 views

Category:

Data & Analytics


0 download

DESCRIPTION

How to use Object Path, the agile query languge, to effectively extract relevant data from JSON documents of complex or even unknown structure. How to quickly build a web app using the insights you discover with ObjectPath.

TRANSCRIPT

Page 1: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

Working with data in JSON format

Adrian Kalbarczyk | Ela Bednarek

Page 2: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

What is JSON?

JSON (JavaScript Object Notation) is:

• a lightweight data-interchange format

• easy for humans to read and write

• easy for machines to parse and generate

Page 3: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

What does JSON look like?

JSON is built on two structures: •An object – a collection of name/value pairs

{ "firstName":"John" , "lastName":"Doe" } •An array - an ordered list of values

[ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" } ]

Page 4: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

What does JSON look like?

A value can be: • a string in double quotes: “a string” • a number: 22 • true or false!• null • an object: {} • an array: []

These structures can be nested.

Page 5: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON
Page 6: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

Why did we build ObjectPath?

• The combination of objects and arrays allows for simple, human-readable representation of all kinds of real life objects

• BUT using JSON's full potential is impossible without an easy way to query complex structures

• In real life data you deal with is messy

Page 7: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

Getting started with ObjectPath

Page 8: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

Getting started with ObjectPathgit clone https://github.com/adriank/ObjectPath.git

cd ObjectPath/ObjectPathPy

./ObjectPath.py -u “https://gdata.youtube.com/feeds/api/videos?q=football&orderby=published&start-index=1&max-results=50&alt=json"

!

(Warning: In China YouTube API doesn’t work without VPN!)

Page 9: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

Data we'll work with today

• Klout API

• YouTube API

• Big geospatial data file from San Francisco (182MB)

• Your own datasets are welcomed!

Page 10: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

Klout APIWhat is the nickname of the person with the highest Klout score that influences Guy Kawasaki?

• $.*

• max($..score)

• $..*[@.score is max($..score).score]

• $..*[@.score.score is max($..score).score]

• $..*[@.score.score is max($..score).score].nick

• $.myInfluencers..*[@.score.score is max($.myInfluencers..score).score].nick[0]

Page 11: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

YouTube API• ./ObjectPath.py -u “https://gdata.youtube.com/feeds/api/

videos?q=football&orderby=published&start-index=1&max-results=50&alt=json"

• $.*

• $..entry[0].link

• $..*[@.title['$t'] is "FIFA 14 | Fails Compilation May 2014!"]..link[@.type is "text/html"][0].href

Page 12: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

CityLots data from SF• Calculating the area of a lots in SF

• https://data.sfgov.org/Other/Data-Catalog/h4ui-ubbu

• We’ll work with data converted to JSON from: https://github.com/zeMirco/sf-city-lots-json

• git clone https://github.com/zeMirco/sf-city-lots-json.git

Page 13: FIFA fails, Guy Kawasaki and real estate in SF - find out about all three by querying JSON

How to build a YT search web app in 10 min?

http://adrian.ap.asyncode.com/index.html#!main=yt/default&ds=/yt/default/fifa