IMPORTJSON not working in Google Sheets? Here is how to add it
You typed =IMPORTJSON(...) and got #NAME?. Google Sheets has IMPORTDATA, IMPORTXML and IMPORTHTML, but no built-in IMPORTJSON. Add a free custom function with the steps below, or use Sheets API Connector Pro, which includes the formula plus a request builder: $39 once.
Add a free IMPORTJSON function
- In your sheet open Extensions > Apps Script.
- Replace the empty file with this code:
function IMPORTJSON(url) { var data = JSON.parse(UrlFetchApp.fetch(url).getContentText()); var rows = Array.isArray(data) ? data : [data]; var keys = Object.keys(rows[0]); return [keys].concat(rows.map(function (r) { return keys.map(function (k) { var v = r[k]; return v !== null && typeof v === 'object' ? JSON.stringify(v) : v; }); })); } - Save, go back to the sheet, and type
=IMPORTJSON("https://example.com/data.json")with your own URL. - If the records are nested, for example under
data, change the line that startsvar rowstovar rows = data.data;
Where the free function stops
This version makes one plain request. It is a good fit for small, public JSON. It does not follow pages, so an API that returns 100 records at a time gives you the first 100. It has no sign-in step, and putting an API key in a cell or in the script exposes it to anyone who can open them. A custom function must also return within Google's time limit for custom functions, and nested objects arrive as JSON text.
What Sheets API Connector adds
=IMPORTJSON(url, recordsPath, fields)for public JSON URLs, with the records path and the columns you want. It shows up to 1,000 rows and caches each URL for 5 minutes. Request and response errors appear as a readable message in the cell.- A sidebar request builder for everything else: GET, POST, PUT, PATCH and DELETE with headers, query parameters, a JSON body and cell references.
- Sign-in with an API key, Bearer token, Basic auth or OAuth 2.0. Your keys stay in your private Google user storage.
- Automatic pagination in 5 styles: page number, offset and limit, cursor, next-URL and Link headers.
- Nested JSON flattened into columns, replace or append mode, and daily or hourly scheduled refresh.
Which one to use in the sheet
Use a formula when the URL is public, the answer fits in one response and you are happy for the sheet to recalculate it. Use the sidebar when the API needs a key, returns pages, or should refresh on a schedule. The formula in Sheets API Connector does not use your saved sign-ins and does not page.
Questions
Why does IMPORTJSON show #NAME? in my sheet?
It is not a built-in Google Sheets function. It exists only in a spreadsheet that has a script or add-on defining it, so a formula copied into a spreadsheet without it stops working.
Can IMPORTJSON use an API key?
The formula in Sheets API Connector works only with public URLs that need no key. For keys and tokens use its sidebar.
Why do I get only the first page of results?
The API splits its answer into pages and a single request returns one of them. The sidebar's pagination setting requests further pages, up to the Max pages you set (10 by default).
Is it a subscription?
The Pro copy edition is $39 once. It is a Google Sheet with the connector built in, unlocked by a licence key, with 60,000 requests a month and up to 100 saved requests. There is a 7-day money-back guarantee.
All features · Pull every page of an API · Setup steps
I make this tool and sell it.