Upload
ela-bednarek
View
566
Download
0
Embed Size (px)
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.
Citation preview
Working with data in JSON format
Adrian Kalbarczyk | Ela Bednarek
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
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" } ]
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.
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
Getting started with ObjectPath
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!)
Data we'll work with today
• Klout API
• YouTube API
• Big geospatial data file from San Francisco (182MB)
• Your own datasets are welcomed!
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]
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
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
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
Contact
http://adriank.github.io/ObjectPath/
http://docs.asyncode.com