How can I get javascript to read from a .json file?

Assuming you mean “file on a local filesystem” when you say .json file.

You’ll need to save the json data formatted as jsonp, and use a file:// url to access it.

Your HTML will look like this:

<script src="\data\activity.jsonp"></script>
<script type="text/javascript">
  function updateMe(){
    var x = 0;
    var activity=jsonstr;
    foreach (i in activity) {
        date = document.getElementById( =;
        event = document.getElementById(i.event).innerHTML = activity.event;

And the file c:\data\activity.jsonp contains the following line:

jsonstr = [ {"date":"July 4th", "event":"Independence Day"} ];

Leave a Comment