For reading the external Local JSON file (data.json) using javascript, first create your data.json file:

data = '[{"name" : "Ashwin", "age" : "20"},{"name" : "Abhinandan", "age" : "20"}]';

Then,

  1. Mention the path of the json file in the script source along with the javascript file

     <script type="text/javascript" src="data.json"></script>
     <script type="text/javascript" src="javascript.js"></script>
    
  2. Get the Object from the json file

     var mydata = JSON.parse(data);
     alert(mydata[0].name);
     alert(mydata[0].age);
     alert(mydata[1].name);
     alert(mydata[1].age);
    
Answer from Ashfedy on Stack Overflow
Discussions

Loading a local .json file with javascript
Also, if you mean "local" in the ... (either locally or remotely, whatever floats your boat). ... Thanks Dave. I am just trying to access a .json file in my .js file however I can. It does not need to be plain javascript. ... One good place to start is reading the jquery doc ... More on teamtreehouse.com
🌐 teamtreehouse.com
1
May 18, 2018
Pulling data from local json file
I have not used json files as of yet, and I am curious on how to get the information out of it. I understand how to parse it which turns it into a javascript object, and then I can use that to populate what I need. However, all the examples I looked at they were creating a string in JavaScript ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
February 8, 2022
Is it really so hard to load a local JSON file?
You are using a webserver to access your HTML? fetch('myJson.json').then(res => res.json()).then(json=>console.log(json)); If you're not running a server locally to run your HTML/JS (going to http://localhost), instead just opening the HTML file in the browser (where the URL is like file:///), I'd definitely recommend using a server.. More on reddit.com
🌐 r/learnjavascript
11
4
February 18, 2022
Read local JSON file using only Javascript
Hello, I am trying to read the content of a local JSON file using vanilla Javascript. So far I have only found one method to do this, which is creating a GET request for the local file like this: var request = new XMLH… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
May 6, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › read-json-file-using-javascript
Read JSON File Using JavaScript - GeeksforGeeks
The fetch() API retrieves JSON files asynchronously and parses them into JavaScript objects. ... <html> <head></head> <body> <script> function fetchJSONData() { fetch('./sample.json') .then(response => { if (!response.ok) { throw new Error(`HTTP ...
Published   January 17, 2026
🌐
GitHub
gist.github.com › laurenancona › bd560948d71054e3d1477e43c4d48cb6
Access local JSON data with Javascript · GitHub
For reading the external Local JSON file (data.json) using java script · data = '[{"name" : "Ashwin", "age" : "20"},{"name" : "Abhinandan", "age" : "20"}]'; // Mention the path of the json file in the script source along with the javascript file.
Find elsewhere
🌐
Reddit
reddit.com › r/learnjavascript › is it really so hard to load a local json file?
r/learnjavascript on Reddit: Is it really so hard to load a local JSON file?
February 18, 2022 -

I'm working on a platformer game in HTML, and have the level data stored in a JSON file. It's right there, in the same folder, and yet I can't find a simple way to access it.
I've seen 2 approaches online, one is to put the entire thing in quotes, then add "data=" to the start, and run it like a JS file. This is beyond stupid, but I'll settle for it if I have to.
The other involves making an actual "server" request to my local machine, but when I try that I get an error in chrome, saying that CORS doesn't allow you to access files using request type null. Other people in the comments were saying it was a bad idea to do that.
Is there seriously no easy way to just say "load this file", without jQuery or node?

Top answer
1 of 3
2
You are using a webserver to access your HTML? fetch('myJson.json').then(res => res.json()).then(json=>console.log(json)); If you're not running a server locally to run your HTML/JS (going to http://localhost), instead just opening the HTML file in the browser (where the URL is like file:///), I'd definitely recommend using a server..
2 of 3
2
Is there seriously no easy way to just say "load this file", without jQuery or node? The other answers describe the how, but to answer the why of this part directly -- it's all about the runtime that the JavaScript code is executing in. jQuery has nothing to do with it (this is just a JavaScript library with some useful functions), but it matters whether the JavaScript is executing inside of a user's web browser, or inside of a server-side environment (including desktop applications). Right now, the "user" is just you developing the game, but the "user" could be anyone. Web browsers do not allow JavaScript code to load arbitrary files from the user's machine. It's not a limitation of the language, it's the runtime (the browser) which disallows this. Imagine if you went to a website and it had JavaScript code that was allowed to read files from your computer! Thankfully, web browsers prevent this from happening. This is why the other comments have suggested hosting the data files (JSON) on a server -- using a NodeJS runtime for example. This runtime allows reading files, because it's not the end-user whose files are being read, it's the developer running the server.
🌐
Oxylabs
oxylabs.io › blog › javascript-read-json-file
How to Read JSON Files in JavaScript: Tutorial
The two syntaxes to load this JSON file are as follows: ... The require() function looks for products.json in the same directory as the script and reads the JSON file in JavaScript object format.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-read-json-file-in-javascript
How to Read a JSON File in JavaScript – Reading JSON in JS
November 7, 2024 - One standard method we can use to read a JSON file (either a local file or one uploaded to a server) is with the Fetch API. It uses the same syntax for both.
🌐
DEV Community
dev.to › roshan_100kar › how-to-read-a-local-json-file-using-fetch-api-21jh
How To Read a local JSON File Using Fetch API - DEV Community
September 25, 2022 - On the other hand, if you are doing NodeJS, you have the fs module to actually read the file system. And in both cases, you can statically import JSON. ... Independent front-end developer Designer, Blogger, Web developer #webdev #webdevelopment #webdesign #programminghumor ... Practical functional programmer, types lover, climber, early days violonist. I build the Measur platform: https://www.measur.co/ ... It's very convenient when you need to mock some external service in a test environment. It means you can read a local file without having to conditionally use require or fs and keep a consistent server application
🌐
CodeHim
codehim.com › home › vanilla javascript › javascript read local json file without jquery
JavaScript Read Local JSON File without jQuery — CodeHim
January 22, 2024 - The following code should be placed within a <script> tag in your HTML document or in an external JavaScript file. (function(){ function onChange(event) { var reader = new FileReader(); reader.onload = onReaderLoad; reader.readAsText(event.target.files[0]); } function onReaderLoad(event){ console.log(event.target.result); var obj = JSON.parse(event.target.result); document.getElementById('fileContent').innerHTML = event.target.result; //alert(event.target.result); } document.getElementById('file').addEventListener('change', onChange); }());
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Read local JSON file using only Javascript - JavaScript - The freeCodeCamp Forum
May 6, 2022 - So far I have only found one method to do this, which is creating a GET request for the local file like this: var request = new XMLHttpRequest(); request.open("GET", "localFolder/example.json", false); request.send(null); var data = ...
🌐
Ionic Framework
forum.ionicframework.com › ionic framework › ionic-v3
Reading local json file - ionic-v3 - Ionic Forum
April 12, 2019 - Is there an easy way to read a local file. Specifically, I want to read a local JSON file and display a menu based on the data. I’ve seen some methods, but they mostly use deprecated code. Is there a better/modern way…
🌐
ScrapingBee
scrapingbee.com › webscraping-questions › json › how-to-parse-a-json-file-in-javascript
How to parse a JSON file in JavaScript? | ScrapingBee
Let's say you have a JSON file containing a list of objects, like the one below: [ {"name": "John Doe", "age": 32}, {"name": "Joe Doe", "age": 30}, {"name": "Alice", "age": 28} ] You can parse this using JSON.parse() just as we did above, except that the function will return a JavaScript array: var fs = require('fs'); fs.readFile('file-with-array.json', 'utf-8', function (err, data) { if (err) throw err; var arr = JSON.parse(data); arr.forEach((obj) => { console.log(`${obj.name} is ${obj.age} years old`) }) });
🌐
iProyal
iproyal.com › blog › javascript-read-json-file
How to Read a JSON File in JavaScript: A Beginner-Friendly Guide
August 26, 2025 - This approach is simple and clean, but it only works with files available at load time, not for dynamic or external JSON file access. In a browser, you can use the fetch API to read a local ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
Many programming environments feature the ability to read (parse) and generate JSON. In JavaScript, the methods for parsing and generating JSON are provided by the JSON object. Note: Converting a string to a native object is called deserialization, while converting a native object to a string so it can be transmitted across the network is called serialization. A JSON string 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.
🌐
LogRocket
blog.logrocket.com › home › reading and writing json files in node.js: a complete tutorial
Reading and writing JSON files in Node.js: A complete tutorial - LogRocket Blog
November 1, 2024 - Just like the fs module, fs-extra has both asynchronous and synchronous methods. You don’t need to stringify your JavaScript object before writing to a JSON file. Similarly, you don’t need to parse to a JavaScript object after reading a JSON file.
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JSON.stringify()
A common use of JSON is to exchange data to/from a web server. When sending data to a web server, the data has to be a string. You can convert any JavaScript datatype into a string with JSON.stringify().