Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Json file from github pages server using javascript [closed]

I am building my website on github pages which can only host a static website. However it does allow use of javascript. So I have a json file on the github server from where my website runs and I want to fetch and process it using javascript. The link to the file is below

https://bioinfobot.github.io/data/2017-05.json

more specifically it is located at data/2017-05.json

If you click on the link above it will show the attributes of my json file.

I tried many tweaks from stack exchange but nothing is working out for me. Can someone please give me a simple code to just to invoke this file to an object. I can do the rest from there on. Thanks.

like image 594
Rohit Farmer Avatar asked May 31 '17 08:05

Rohit Farmer


People also ask

How can I get JavaScript to read from a .JSON file?

To fix this error, we need to add the file type of JSON to the import statement, and then we'll be able to read our JSON file in JavaScript: import data from './data. json' assert { type: 'JSON' }; console. log(data);

Does GitHub Pages support JSON?

By using Github, we can host our JSON files data there, because it is a static site, the only limitation is that it only supports GET requests.


1 Answers

You can try this using jquery

 $.getJSON("https://bioinfobot.github.io/data/2017-05.json")
    .done(function( data ) {
       console.log(data)
    });

OR

$.getJSON("https://bioinfobot.github.io/data/2017-05.json", function(json) {
    console.log(json); 
});
like image 157
Manoj Avatar answered Nov 15 '22 00:11

Manoj