You can import only .ts or .tsx file using typescript imports. I tried it this morning and fetch api is unable to read a local json file with file:// scheme. Binary files (EXE, PNG, MP4 etc) can be read using readAsBinaryString() / readAsArrayBuffer() methods. A generic URL has the following form: In this tutorial, we will see how to Load JSON file locally using pure Javascript. This approach looks so clean but you can't use it for local files – keysl May 18 '18 at 3:55. A Uniform Resource Locator (URL), is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it.A web resource is any data that can be obtained via web, such as HTML documents, PDF files, PNG images, JSON data, or plain text. This can be done in two ways: a)if you want to import JSON you may have to use "require" b) Copy the json and assign the JSON to a varaible and store it in a .ts file . 1. @keysl OK, I guess it probably has to be that way for security reasons. the proper way to include or load the JSON file in a web application, Instead of using JQuery we'll The correct method using XMLHttpRequest JavaScript Alternative To jQuery's Having a pure javascript alternative t The readFile and readFileSync functions will read JSON data from the file in an asynchronous and synchronous manner, respectively. I am assuming ‘without using Ajax’ you mean by a local json data in your system. These files can be read from or, of course, appended too. As described above, a JSON is a string whose format very much resembles JavaScript object literal format. However, require is synchronous and can only read JSON data from files with '.json' extension. A JSON object can be stored in its own file, which is basically just a text file with an extension of .json, and a MIME type of application/json.. JSON structure. To access a local file on a server, you could simply write the path of your JSON in you web browser. Reading a File and Getting its Binary Data in Javascript In this case the variable will hold the json object . One good place to start is reading the jquery doc link $.getJSON and follow that up with the MDN Working with JSON.
If that is the case you can easily import the local json data file into your HTML file by just including the json file in your head tag e.g. Text files (TXT, CSV, JSON, HTML etc) can be read with readAsText() method. Normally, the idea is to go to the location of the file (or download it if you prefer).

If you have a local *amp stack dev environment, here's some code to get started (basically from the jquery doc example) It’s virtually a text file but contains well-formatted data in the style of JavaScript Object Notation. Then we use XLSX which an inbuilt facility of SheetJS js-xlsx to convert our binary string into a JSON object. URL. The first time I saw the .json file I was pretty confused, I always thought of JSON only belonging within the browser.
From this FileReader we can read the data in our excel file as a binary string. Loading local JSON file. You can also use the global require method to handle reading/parsing JSON data from a file in a single line of code.