Jump to content

Setting a constant equal to an external JSON file

Recommended Posts

I am attempting to set an array equal to an external JSON file. I put the JSON file on google drive and set it to share. I have tried many different examples of code to get the JSON data into the array, but I am stymied. Thanks for any help.

Edited by JamesJ
Link to comment
  • Replies 2
  • Views 209
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thanks for the response method.

I did try this code to read the following simple json file. I uploaded the file to the squarespace site rather than trying to call it from google drive. 

<script>
fetch('https://www.waileage.org/s/testdata.json')
  .then(response => response.json())
  .then(data => console.log(data));
  document.getElementById("container").innerHTML = data;
  </script>

 

json file = [
['apple', 'fruit', 'red'], 
['pear', 'fruit', 'yellow'], 
['carrot', 'vegetable', 'orange'], 
['eggplant', 'vegetable', 'purple']
]

Edited by JamesJ
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.