Importing JSON is a powerful way to pull data from public data sources to store, enrich or analyse. While Google Sheets offers a built-in
=ImportData() function that can retrieve JSON data, we recommend using a trusted community script that adds an
=ImportJSON() function to Google Sheets. With ImportJSON the JSON data gets transformed so that it’s correctly formatted in rows and columns in your spreadsheet.
Let’s use ImportJSON to retrieve data from an API endpoint. For this example we'll use CoinDesk's historical price of Bitcoin:
- To begin, create a new Google Sheet.
- Click on the Tools menu and select the option Script editor. This will open a new Google Apps Script tab.
- In the code window, delete the default placeholder function to leave a blank window.
- Head over to the Gist containing the ImportJSON script.
- Click the Raw button in the top right corner of the script window to select all and copy the entire code.
- Return to your empty script editor window and paste the script code.
- From the menu, select File > Save.
- Name your code "ImportJSON".
- Close the Script editor and navigate back to your Google Sheet tab.
- In cell A1, enter
=ImportJSON(“https://api.coindesk.com/v1/bpi/historical/close.json”). Be sure to keep the quotes
- Press Enter. Your Google Sheet should now populate with your JSON data.
“url”, there are two additional parameters you can use with
“query”– a comma-separated list of paths to import. Any path starting with one of these paths gets imported. (Example:
“parseOptions”– a comma-separated list of options that alter processing of the data. (Example:
If ImportJSON has whetted your appetite for more importing of API data in Google Sheets, you might want to consider some of the other advanced Google Sheets functions out there, an automated option like Apipheny or Supermetrics, or visualizing the data you've imported using Geckoboard.