Import JSON data into single cell in google sheets
Question: 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


Answer: 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](https://developers.google.com/apps-script/guides/sheets/functions)
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](https://github.com/fastfedora/google-
docs/blob/master/scripts/ImportJSON/Code.gs) may be helpful.

