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

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 do I load a JSON file? - JavaScript - Kotlin Discussions
Hey! I’m learning how to work with Kotlin and Javascript, and right now, I’m trying to load a .json file that’s present on the same server the website itself is hosted from. How would I go about this? There’s a JSON object but the documentation doesn’t really say how to use it. Thanks! More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
0
September 1, 2017
[deleted by user]
You can't write files directly to the user's filesystem from JS in the browser, no. And you can only read files that the user has selected with a file input. What you can do is create an ad-hoc file from data you have, and then trigger the browser's download prompt (or save it to the user's downloads folder, if they have automatic downloads turned on). For example, here is how you can take a table from a page and prompt the user to download it as a .CSV file: Sarah New York Masseuse Laura Odessa Journalist Leland Vancouver Ski Instructor Save as .csv file The idea is that you create a new link element that points to data:, and then some content, set the download attribute on it so that clicking it prompts a download rather than an attempt to render it in the browser, attach it to the DOM, call the click method on it, then remove it from the DOM. You could do this for all sorts of binary data, locally stored data, etc too, and it's as close as you'll get. That technique relies on the HTML5 download attribute, so it won't work in IE <= 10. But those browsers have the navigator.msSaveBlob method which is even simpler. More on reddit.com
🌐 r/javascript
28
41
October 24, 2016
Using ONLY normal, pure JS, how do I read a json file
AJAX is not a library, it is 'normal pure JS'. Maybe try listening more carefully to what people are telling you instead of being so quick to dismiss them. Javascript does have JSON.parse() which will turn a JSON string into an object- this is the subject of the entire first page of google results for a simple search like 'javascript read json'. There are also more specific utilities for reading JSON in the context of things like the browser fetch API. Are you talking about doing this in the browser, or doing it with Node? In the browser you can't access the file system, but you can access files served over HTTP: fetch('http://my-server.com/file.json') .then((res) => res.json()) .then(console.log) In Node you can talk directly to the file system, like so: const fs = require('fs'); fs.readFile('/path/to/file.json', { encoding: 'utf8' }, (err, data) => { if (err) throw err; console.log(JSON.parse(data)); }); More on reddit.com
🌐 r/learnjavascript
9
0
August 9, 2019
🌐
W3Schools
w3schools.com › js › js_json_parse.asp
JSON.parse()
Parse the data with JSON.parse(), and the data becomes a JavaScript object.
🌐
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.
🌐
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 ...
🌐
W3Schools
w3schools.com › js › js_json.asp
JavaScript JSON
JavaScript has a built in function for converting JSON strings into JavaScript objects: ... You can receive pure text from a server and use it as a JavaScript object.
🌐
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
🌐
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.
🌐
Quora
quora.com › What-is-the-best-way-to-load-and-parse-JSON-files-into-JavaScript-objects
What is the best way to load and parse JSON files into JavaScript objects? - Quora
Node? There is the JSON.parse() method once you’ve got it as text, but you need to look to your platform of choice as to how to get that text. If you’re in Node (you mention files) look at the fs mod...
🌐
Linux Tip
linuxscrew.com › home › programming › javascript › how to read a local/remote json file in javascript [examples]
How to Read a Local/Remote JSON File in JavaScript [Examples]
November 28, 2021 - The second then statement then contains the parsed JSON file ready for use – in this case, it’s simply logged to the console for inspection. The FileReader object, a relatively recent addition to HTML5 and JavaScript, allows you to read files stored locally on your computer directly into JavaScript running in a browser, without the need to first upload it to a server.
🌐
Mkyong
mkyong.com › home › javascript › how to access json object in javascript
How to access JSON object in JavaScript - Mkyong.com
October 12, 2013 - To access the JSON object in JavaScript, parse it with JSON.parse(), and access it via “.” or “[]”.
🌐
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"] // } ...
🌐
Stack Abuse
stackabuse.com › bytes › how-to-import-a-json-file-in-javascript-node-js
How to Import a JSON File in JavaScript/Node.js
September 18, 2023 - Importing a JSON file in Node.js is very easy to do since JSON is a native type to JS. You can use the built-in fs (file system) module to read the file, and then parse it into a JavaScript object using JSON.parse().
🌐
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....
🌐
Kotlin Discussions
discuss.kotlinlang.org › javascript
How do I load a JSON file? - JavaScript - Kotlin Discussions
September 1, 2017 - Hey! I’m learning how to work with Kotlin and Javascript, and right now, I’m trying to load a .json file that’s present on the same server the website itself is hosted from. How would I go about this? There’s a JSON ob…
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
2 weeks ago - Source code: Lib/json/__init__.py JSON (JavaScript Object Notation), specified by RFC 7159(which obsoletes RFC 4627) and by ECMA-404, is a lightweight data interchange format inspired by JavaScript...
🌐
CSVJSON
csvjson.com
CSVJSON - CSVJSON
Online Conversion Tools for Developers. CSV, JSON, SQL and JavaScript. Sponsored by Flatfile.
🌐
MapLibre
maplibre.org › maplibre-gl-js › docs
MapLibre GL JS Documentation - MapLibre GL JS
We recommend using the VS Code extension to catch any misspellings before making your PR. You can run npx cspell "docs/**/*.html" "docs/**/*.md" from the CLI to check all files. If there's a false-positive (a technical term which isn't in the default dictionary) you can add it to the .spell.json file's words array in the root.
🌐
Medium
frontendinterviewquestions.medium.com › how-to-load-json-file-from-desktop-using-javascript-61a311f7c771
How to load json file from desktop using JavaScript ? | by Pravin M | Medium
October 5, 2024 - In this HTML file, we have a button to trigger the loading of the JSON data and a <pre> element to display the output. Now, create a file named script.js in the same directory as your HTML file. This file will contain the JavaScript code to ...