$.getJSON is asynchronous so you should do:

$.getJSON("test.json", function(json) {
    console.log(json); // this will show the info it in firebug console
});
Answer from seppo0010 on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-open-json-file
How to Open JSON File? - GeeksforGeeks
July 23, 2025 - Open a text editor on your computer (such as Notepad, TextEdit, or VS Code). Create a new file. Save the file with the .json extension (e.g., sample.json). Copy the following sample JSON code and paste it into your file, then save it again.
🌐
Oxylabs
oxylabs.io › blog › javascript-read-json-file
How to Read JSON Files in JavaScript: Tutorial
Using the Fetch API method, this JavaScript function retrieves a JSON file from a given URL. If the network response is successful, it parses data into a JSON string and displays the results using the displayProducts() method.
Discussions

javascript - Loading local JSON file - Stack Overflow
In fact, what this is not actually ... a Javascript object. This technique will not work for true JSON files." 2018-07-12T14:30:06.9Z+00:00 ... honestly this is a great solution if you just have some pre-canned data and u want to serve a static page 2019-11-27T21:54:31.73Z+00:00 ... @lesolorzanov - the browser is still going to block it because of the same origin policy. 2023-02-16T16:34:26.11Z+00:00 ... // required use of an anonymous callback, // as .open() will NOT ... More on stackoverflow.com
🌐 stackoverflow.com
How to read an external local JSON file in JavaScript? - Stack Overflow
The CORS policy makes this kind ... to actually open a file, you'd have to run a web server which can manage those requests. 2019-12-30T22:37:34.24Z+00:00 ... Very simple. Rename your json file to ".js" instead ".json". More on stackoverflow.com
🌐 stackoverflow.com
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
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
🌐
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 - But a quick tip that differentiates ... reads a JSON file in JavaScript by sending an HTTP request, while the import statement does not require any HTTP request but rather works like every other import we make.
🌐
OpenReplay
blog.openreplay.com › how-to-read-and-write-json-in-javascript
How to Read and Write JSON in JavaScript
Note that JSON.parse() accepts a valid JSON string value and returns a JavaScript value. 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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
The very last thing we do is to append the <h2>, <p>s, and <ul> inside the <article> (myArticle), then append the <article> inside the <section>. The order in which things are appended is important, as this is the order they will be displayed inside the HTML. Note: If you are having trouble getting the example to work, try referring to our heroes-finished.html source code (see it running live also.) Note: If you are having trouble following the dot/bracket notation we are using to access the JavaScript object, it can help to have the superheroes.json file open in another tab or your text editor, and refer to it as you look at our JavaScript.
Find elsewhere
🌐
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
🌐
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. You can send a JavaScript object to a server in pure text format.
🌐
Delft Stack
delftstack.com › home › howto › javascript › load json file in javascript
How to Load JSON File in JavaScript | Delft Stack
March 4, 2025 - One of the most straightforward methods to load a JSON file in JavaScript is by using the Fetch API. This modern approach allows you to make network requests similar to XMLHttpRequest.
🌐
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.
🌐
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 - Therefore, it is advisable to use require for loading static JSON files such as configuration files that don’t change often. Don’t use require if the JSON file you load keeps changing, because it will cache the loaded file, and use the cached version if you require the same file again. Your latest changes will not be reflected. Assuming you have a config.json file with the following contents: ... You can load the config.json file in a JavaScript file using the code below.
🌐
GitHub
gist.github.com › laurenancona › bd560948d71054e3d1477e43c4d48cb6
Access local JSON data with Javascript · GitHub
To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ... Original Question on Stack Exchange. 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.
🌐
Koladechris
koladechris.com › blog › how-to-import-a-json-file-in-javaScript
How to Import a JSON File in JavaScript
Learn how to import a JSON file in JavaScript, handle common errors, and explore a practical alternative.
🌐
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.

🌐
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.
🌐
ScrapingBee
scrapingbee.com › webscraping-questions › json › how-to-parse-a-json-file-in-javascript
How to parse a JSON file in JavaScript? | ScrapingBee
In JavaScript, you can parse a JSON string using the JSON.parse() method. A JSON file is essentially a text file containing a JSON string.
🌐
HeyNode
heynode.com › tutorial › readwrite-json-files-nodejs
Read/Write JSON Files with Node.js | HeyNode
The simplest way to read a JSON file is to require it. Passing require() with the path to a JSON file will synchronously read and parse the data into a JavaScript object.