简体   繁体   中英

Import JSON data into single cell in google sheets

I am wondering if anyone can give me an example on how to gather data from a JSON file, and import it into a single cell in google sheets? It does not need to be formatted or copied to multiple cells, it simply needs to take the entire contents of the JSON and copy it into a single cell. The file I am working with is also a local file. Can anyone shed some light? It does not necessarily need to use google apps script, if a python script or anything similar could do the same thing that would be ok

First of all, Google Sheets cannot access your local files. It's a web application, so any external data it gets must be accessible from the Internet.

If your goal is simply to put the contents of a web-accessible JSON file in a single cell, the following custom function will do the job:

function import(url) {
  return UrlFetchApp.fetch(url).getContentText();
}

This simply grabs whatever page you point at, and crams its contents in a cell. Example: =import("http://xkcd.com/info.0.json")


If you do decide to parse JSON, be advised there isn't anything suitable built into Google Sheets at present. The project importJSON by Trevor Lohrbeer may be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM