Products
Features
YouTube Video Summarizer
Summarize YouTube videos
Web & PDF Highlighter
Highlight web pages & PDFs
Chat with PDF
Ask any PDF questions with AI
Ask AI Clone
Chat with your highlights & memories
Audio Transcriber
Transcribe audio files to text
Glasp Reader
Read and highlight articles
Kindle Highlight Export
Export your Kindle highlights
Idea Hatch
Hatch ideas from your highlights
Integrations
Obsidian Plugin
Notion Integration
Pocket Integration
Instapaper Integration
Medium Integration
Readwise Integration
Snipd Integration
Hypothesis Integration
Apps & Extensions
Chrome Extension
Safari Extension
Edge Add-ons
Firefox Add-ons
iOS App
Android App
Discover
Discover
Ideas
Discover new ideas and insights
Articles
Curated articles and insights
Books
Book recommendations by great minds
Posts
Essays and notes from readers
Quotes
Inspiring quotes collection
Videos
Curated videos and summaries
Explore Glasp
Glasp Newsletter
Weekly insights and updates
Glasp Talk
Interview series with great minds
Glasp Blog
Latest news and articles
Glasp Use Cases
Learn how others use Glasp
Build & Support
Glasp API
Access Glasp's API for developers
MCP Connector
Connect Glasp to Claude & ChatGPT
Community
Glasp Reddit Community
Students
Student discount and benefits
FAQs
Frequently Asked Questions
AboutPricing
DashboardLog inSign up

10.4: Loading JSON data from a URL (Asynchronous Callbacks!) - p5.js Tutorial

461.8K views
•
October 30, 2015
by
The Coding Train
YouTube video player
10.4: Loading JSON data from a URL (Asynchronous Callbacks!) - p5.js Tutorial

TL;DR

Learn how to load JSON data from a URL in p5.js using the loadJSON function and asynchronous callbacks.

Transcript

In this video, I want to look at loading JSON data not from a local file-- like a file like birds.json that's right there in your project-- but from a URL. And this is one step along the way to querying an API, to saying like, hey, weather map thing, give me some weather data. Or, hey, New York Times, give me some New York Times data. But I want to... Read More

Key Insights

  • 👻 The loadJSON function in p5.js allows for easy loading of JSON data from a URL by replacing the local file name in the preload function.
  • 🪡 Asynchronous data loading is necessary for scenarios where data needs to be fetched dynamically during program execution.
  • 💨 Callback functions are used to handle the data when it arrives, providing a way to continue program execution without waiting for the data to load.
  • 🍵 JavaScript in general, and p5.js specifically, provide methods like loadJSON to handle data loading and asynchronous operations.
  • 💦 Working with external APIs or data sources often require using techniques like JSONP to overcome security restrictions.
  • 💐 By using if statements and booleans, you can control the flow of your program and ensure that data is loaded before using it for visualizations.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How do you load JSON data from a URL in p5.js?

To load JSON data from a URL, use the loadJSON function and pass the URL as the first argument and a callback function as the second argument. The callback function will be triggered when the data is loaded.

Q: What is the difference between preload and loadJSON functions in p5.js?

The preload function is used to load data before the program starts, ensuring that all the data is available from the beginning. On the other hand, the loadJSON function loads data asynchronously, allowing the program to continue running while the data is being fetched.

Q: How can you ensure that the data has finished loading before using it in p5.js?

In p5.js, you can use asynchronous callbacks to handle data loading. The callback function is triggered when the data is loaded, and it should be defined with a parameter that p5.js will fill with the loaded data. This way, you can ensure that the data is available for use in your program.

Q: What is JSONP, and why is it sometimes necessary to use it?

JSONP (JSON with padding) is a technique to bypass the same-origin policy and allow cross-origin data access. It involves adding a callback parameter to the URL when fetching JSON data. JSONP is useful when the server doesn't have the appropriate CORS headers set, preventing the usual access to the data.

Summary & Key Takeaways

  • The p5.js library allows for easy loading of JSON data from a URL, by replacing the local file name with a URL.

  • Preloading data using the preload function is not suitable for scenarios where data needs to be loaded dynamically, such as fetching weather data or financial data that continuously changes.

  • To load data asynchronously, use the loadJSON function with a callback function to handle the data when it arrives.

  • The callback function should be defined with a parameter, and p5.js will automatically fill that parameter with the loaded data.


Read in Other Languages (beta)

English

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Explore More Summaries from The Coding Train 📚

Computer Mouse Conference Demos! (node.js + tensorflow.js) thumbnail
Computer Mouse Conference Demos! (node.js + tensorflow.js)
The Coding Train
8.1: Fractals - The Nature of Code thumbnail
8.1: Fractals - The Nature of Code
The Coding Train
Coding Challenge #116: Lissajous Curve Table thumbnail
Coding Challenge #116: Lissajous Curve Table
The Coding Train
ITP/IMA Winter Show 2018 thumbnail
ITP/IMA Winter Show 2018
The Coding Train
Coding Challenge #126: Toothpicks thumbnail
Coding Challenge #126: Toothpicks
The Coding Train
Text Generation using Spell with Nabil Hassein thumbnail
Text Generation using Spell with Nabil Hassein
The Coding Train

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Apps & Extensions

  • Chrome Extension
  • Safari Extension
  • Edge Add-ons
  • Firefox Add-ons
  • iOS App
  • Android App

Key Features

  • YouTube Video Summarizer
  • Web & PDF Summarizer
  • Web & PDF Highlighter
  • Chat with PDF
  • Ask AI Clone
  • Audio Transcriber
  • Glasp Reader
  • Kindle Highlight Export
  • Idea Hatch

Integrations

  • Obsidian Plugin
  • Notion Integration
  • Pocket Integration
  • Instapaper Integration
  • Medium Integration
  • Readwise Integration
  • Snipd Integration
  • Hypothesis Integration

More Features

  • APIs
  • MCP Connector
  • Blog & Post
  • Embed Links
  • Image Highlight
  • Personality Test
  • Quote Shots

Company

  • About us
  • Blog
  • Community
  • FAQs
  • Job Board
  • Newsletter
  • Pricing
Terms

•

Privacy

•

Guidelines

© 2026 Glasp Inc. All rights reserved.