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
🌐
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
Discussions

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
0
May 6, 2022
How to import json files in js
Currently there is no way to directly import JSON files using JavaScript (ESM). You could load them in as data, but that would be going through a separate (usually asynchronous) API rather than using the module system such as fetch . If you're using a bundler (e.g. webpack, rollup, esbuild, etc.), they usually allow you to specify JSON in import statements from within your source code. Then, during bundling, those import statements are re-written to include your JSON through alternate means despite, to you, it appears to work no differently than any other source file. In the future we should be able to do this without the help of bundlers. For more information on that proposed feature, see: https://github.com/tc39/proposal-json-modules More on reddit.com
🌐 r/learnjavascript
9
1
May 30, 2023
How to import and use data from a JSON file (simply)
There are countless ways to do this in JS... What is your use case? Is it just a static file (file path and content doesn't really change) that you just want to import the data into your code? More on reddit.com
🌐 r/learnjavascript
14
0
March 23, 2025
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
🌐
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 - The fetch API is the preferable method to use when we want to read a JSON file either from an external server or local file into our JavaScript file.
🌐
CoreUI
coreui.io › answers › how-to-read-a-json-file-in-javascript
How to read a JSON file in JavaScript · CoreUI
December 3, 2025 - The most straightforward approach ... loading while handling parsing errors gracefully. Use fetch API with the json() method to read and parse JSON files automatically....
🌐
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`) }) });
🌐
Rayobyte
rayobyte.com › blog › javascript-load-json-file-from-descktop
How to JavaScript Load JSON File From Desktop || Rayobyte
September 23, 2024 - In order to use fetch () API to read JSON files, you will need to follow these steps. Create a JSON file. Add the data to that file. Open the JavaScript File.
Find elsewhere
🌐
Geshan
geshan.com.np › blog › 2024 › 10 › nodejs-read-json-file
How to Read a JSON File Using Node.js - Geshan Manandhar
October 30, 2024 - Reading a JSON (JavaScript Object Notation) file in Node.js is a common task for web developers, especially those working with backend and server-side applications. This tutorial will guide you through the process, breaking down the steps to efficiently read JSON files using both the native Node.js fs module and the fs-extra npm package.
🌐
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 = ...
🌐
Quora
quora.com › In-JavaScript-how-do-I-read-a-local-JSON-file
In JavaScript, how do I read a local JSON file? - Quora
Answer (1 of 13): It depends on what environment we're talking about. JavaScript now runs client- and server-side. Client side JavaScript is mostly found in browsers (Chrome, Firefox, Safari), and IE. Server side JavaScript is primarily nodejs. If you are talking about reading JSON from a local ...
🌐
OpenReplay
blog.openreplay.com › how-to-read-and-write-json-in-javascript
How to Read and Write JSON in JavaScript
In case of invalid JSON data, it throws a SyntaxError. Vanilla JavaScript does not allow you to deal with the file system, but you can do it in your back-end with Node.js. In detail, the native fs module enables you to watch, read, and write files in the file system of your back-end application.
🌐
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.
🌐
iProyal
iproyal.com › blog › javascript-read-json-file
How to Read a JSON File in JavaScript: A Beginner-Friendly Guide
August 26, 2025 - A JSON file holds structured JSON data you can convert easily into a JavaScript object using - JSON.parse() or require(). In the browser, use the fetch API method and check the response object before parsing the file.
🌐
Squash
squash.io › how-to-read-an-external-local-json-file-in-javascript
How to Read an External Local JSON File in Javascript
To read an external local JSON file in JavaScript, you can use the XMLHttpRequest object or the fetch() function.
🌐
W3Schools
w3schools.com › js › js_json_parse.asp
JSON.parse()
Parse the data with JSON.parse(), and the data becomes a JavaScript object.
🌐
Medium
frontendinterviewquestions.medium.com › how-to-read-a-json-file-in-javascript-c47e21e9f49a
How to Read a JSON File in JavaScript? | by Pravin M | Medium
August 9, 2024 - In a browser environment, the fetch API is commonly used to read a JSON file from a server. // Example JSON file: data.json // { // "name": "John Doe", // "age": 30, // "isStudent": false, // "courses": ["JavaScript", "HTML", "CSS"] // } ...
🌐
Reddit
reddit.com › r/learnjavascript › how to import a json file into a javascript file to read and then output to the browser?
r/learnjavascript on Reddit: How to import a JSON file into a javascript file to read and then output to the browser?
January 11, 2022 -

I have a simple html file:

<!DOCTYPE html>

<html>
	<head>
		<meta charset="utf-8">
		<meta name="Dashboard">
		<title>Dashboard</title>
	</head>

	<body>
		<script type="text/javascript" src="update.js"></script>	
		<h1>Price of Stocks:</h1>
		<h2 id="ap">Apple: </h2>
		<h2 id="ts">Tesla: </h2>
		<button onclick="updatePrice();">update</button>
	</body>


</html>

update.js looks like this:

const src = require("./prices.json");

function updatePrice() {
	document.getElementById("ap").innerHTML = "Apple: " + src.Apple.price;
	document.getElementById("ts").innerHTML = "Tesla: " + src.Tesla.price;
};

The json file is as follows: (prices are arbitrarily entered right now)

{
	"Apple": {
            "price": 10.0
	},

	"Tesla": {
	    "price": 10.0
	}
}

This html file is not on a webserver and loads directly from C://, the prices.json and update.js are located in the same directory as index.html

The main issue here is that I cannot use require outside of node.js, I know I can use browserify, but surely there is a better way to read data from that json file.