Here's an example that doesn't require jQuery:

function loadJSON(path, success, error)
{
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function()
    {
        if (xhr.readyState === XMLHttpRequest.DONE) {
            if (xhr.status === 200) {
                if (success)
                    success(JSON.parse(xhr.responseText));
            } else {
                if (error)
                    error(xhr);
            }
        }
    };
    xhr.open("GET", path, true);
    xhr.send();
}

Call it as:

loadJSON('my-file.json',
         function(data) { console.log(data); },
         function(xhr) { console.error(xhr); }
);
Answer from Drew Noakes on Stack Overflow
๐ŸŒ
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); }());
๐ŸŒ
W3Frontend
w3frontend.com โ€บ home โ€บ vanilla js โ€บ javascript read local json file without jquery
JavaScript Read Local JSON File without jQuery - W3Frontend
November 23, 2025 - This tutorial will guide you through the process of creating a solution using JavaScript to read local JSON files without relying on the jQuery library.
๐ŸŒ
Talkerscode
talkerscode.com โ€บ howto โ€บ javascript-read-local-json-file-without-jquery.php
JavaScript Read Local JSON File Without jQuery
<!DOCTYPE html> <html lang = " en " > <head> <meta charset = " UTF - 8" > <meta http-equiv = " X-UA-Compatible " content = " IE=edge " > <meta name = " viewport " content = " width = device-width , initial-scale = 1.0 " > <title>javascript read local json file without jquery</title> <style> h1 { font-size : larger ; font-weight : bolder ; color : rgb(113, 221, 113) ; text-align : center ; } h3 { text-align : center ; } </style> </head> <body> <h1> TALKERSCODE </h1> <h3> javascript read local json file without jquery </h3> <script> fetch("file.json") .then(Response => Response.json()) .then(data => { console.log(data) }) </script> </body> </html>
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ Is-there-any-possible-to-read-a-JSON-file-without-jQuery
Is there any possible to read a JSON file without jQuery? - Quora
Answer (1 of 2): Oh sweet baby Linusโ€ฆ Yes. jQuery is a library of convenient functions, built on top of JavaScript. Literally everything jQuery does, modern JavaScript does faster and better. Have some JSON documentation. When it comes to modern libraries, my favourite for handling such stuff ...
๐ŸŒ
Geekstrick
geekstrick.com โ€บ home โ€บ javascript โ€บ load json file locally using pure javascript
Load JSON file locally using pure Javascript - Geekstrick
July 31, 2019 - Load JSON file locally using pure Javascript | Use XMLHttpRequest Request to load JSON File In Web Application. | Load JSON file using Pure JavaScript Instead of jQuery. | Geeks Trick - Code In A Tricky Way
๐ŸŒ
Quora
quora.com โ€บ How-do-you-access-data-from-an-external-JSON-file-to-be-used-in-a-Javascript-file-without-JQuery-in-Notepad
How to access data from an external JSON file to be used in a Javascript file (without JQuery) in Notepad - Quora
Answer (1 of 3): Firstly notepad is not relevant to the question: no IDE or editor will write your code for you. That said, there's no particularly good reason to use it for JavaScript except as a personal challenge. The correct way to load it is through an HTTP request: using the XMLHttpRequest...
๐ŸŒ
Blogger
shopnflgamepass.blogspot.com โ€บ 2021 โ€บ 07 โ€บ javascript-read-local-json-file-without-jquery.html
40 Javascript Read Local Json File Without Jquery - Javascript Answer
js modules (like fs) Modules in the node_modules folder Require can look around for files within the following order: Built-in core Node ... ... Another use case of links with the javascript:void(0) reference is that sometimes, a link may run some JavaScript code in the background, a...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-import-local-json-file-data-to-my-javascript-variable
How to import local json file data to my JavaScript variable?
We have an employee.json file in a directory, within the same directory we have a js file, in which we want to import the content of the json file.The content of employees.json โˆ’employees.json"Employees" : [ { "userId":"ravjy", "jobTitleName
๐ŸŒ
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 ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-load-a-true-JSON-file-using-pure-JavaScript
How to load a true JSON file using pure JavaScript - Quora
Answer (1 of 5): If I am not wrong, you want to load a JSON file without using any JS library such as JQuery. If you use JQuery , loading a JSON file is quite easy, just like following code snippet. [code]$.getJSON("file.json", function(json) { console.log(json); // show the JSON file content i...
๐ŸŒ
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.
Top answer
1 of 2
16

Here's a way to do it without jQuery.

First create this function:

function loadJSON(callback) {   
  var xobj = new XMLHttpRequest();
  xobj.overrideMimeType("application/json");
  xobj.open('GET', '../news_data.json', true);
  xobj.onreadystatechange = function () {
    if (xobj.readyState == 4 && xobj.status == "200") {
      callback(JSON.parse(xobj.responseText));
    }
  };
  xobj.send(null);  
}

Then you can use it by simply calling something like this:

loadJSON(function(json) {
  console.log(json); // this will log out the json object
});

I found this by simply googling "read local json file javascript" (source)

2 of 2
3

You can use jQuery.getJSON() in jquery

First add jquery CDN :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Now set full json file path as ex :- folder/file.json

Description: Load JSON-encoded data from the server using a GET HTTP request.

$.getJSON( "JSON FILE PATH", function( data ) {

    console.log(data); //json output 
});

DEMO

(function() {
  var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
  $.getJSON( flickerAPI, {
    tags: "mount rainier",
    tagmode: "any",
    format: "json"
  })
    .done(function( data ) {
      $.each( data.items, function( i, item ) {
        $( "<img>" ).attr( "src", item.media.m ).appendTo( "#images" );
        if ( i === 3 ) {
          return false;
        }
      });
    });
})();
 img {
    height: 100px;
    float: left;
  }
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.getJSON demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<div id="images"></div>

</body>
</html>