Skip to content

Instantly share code, notes, and snippets.

@robynitp
Last active August 29, 2015 14:16
Show Gist options
  • Save robynitp/52093848a2f65ff44ad0 to your computer and use it in GitHub Desktop.
Save robynitp/52093848a2f65ff44ad0 to your computer and use it in GitHub Desktop.
Reading JSON with p5.js
<!DOCTYPE HTML>
<html>
<head>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.2/p5.js"></script>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.2/addons/p5.dom.js"></script>
<script language="javascript" type="text/javascript" src="sketch.js"></script>
</head>
<body>
<h1>Hello JSON</h1>
</body>
</html>
{
"Title": "The Graduate",
"Year": "1967",
"Rated": "Approved",
"Released": "22 Dec 1967",
"Runtime": "106 min",
"Genre": [
"Comedy",
"Drama",
"Romance"
],
"Director": "Mike Nichols",
"Writers": [
"Calder Willingham (screenplay)",
"Buck Henry (screenplay)",
"Charles Webb (based on the novel by)"
],
"Actors": [
"Anne Bancroft",
"Dustin Hoffman",
"Katharine Ross",
"William Daniels"
],
"Plot": "Ben has recently graduated college, with his parents now expecting great things from him. At his \"Homecoming\" party, Mrs. Robinson, the wife of his father's business partner, has Ben drive her home, which leads to an affair between the two. The affair eventually ends, but comes back to haunt him when he finds himself falling for Elaine, Mrs. Robinson's daughter.",
"Language": "English",
"Country": "USA",
"Awards": "Won 1 Oscar. Another 22 wins & 13 nominations.",
"Poster": "http://ia.media-imdb.com/images/M/MV5BMTQ0ODc4MDk4Nl5BMl5BanBnXkFtZTcwMTEzNzgzNA@@._V1_SX300.jpg",
"imdbRating": "8.1",
"imdbVotes": "183,131",
"imdbID": "tt0061722"
}
function setup() {
noCanvas();
var jsonFile = 'movie.json'; // you can also use a URL here instead
loadJSON(jsonFile,parseStuff);
}
function parseStuff(data){
console.log(data); // the whole thing
console.log("output some other pieces of the API here");
createP("something from the api");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment