Apply Now Apply Now Apply Now
header_logo
Post thumbnail
WEB DEVELOPMENT

How to Open a JSON File in 2026: Windows, Mac, Online & Code Editors

By Abhishek Pati

Not sure how a JSON file works? Learning how to open a JSON file is easier than it sounds — most devices already have what you need built in.

JSON files store data in plain text, so you don’t need any special software to view them. Whether you’re on Windows, Mac, or just want a quick online tool, opening one takes just a few clicks.

Table of contents


  1. TL;DR Summary
  2. What Is a JSON File?
  3. How to Create a JSON File
  4. How to Open a JSON File
    • Opening a JSON File on Windows:
    • Opening JSON File on Mac:
    • Opening JSON File Online:
    • Opening JSON File in Code Editors:
  5. Which Tool Should You Use to Open a JSON File?
  6. How to Read a JSON File
  7. How to Edit a JSON File
  8. Best Practices for Working with JSON Files
  9. Conclusion
  10. FAQs
    • Can I open a JSON file with Notepad?
    • What program opens JSON files by default?
    • Can I open a JSON file in Excel?
    • Do I need special software to open a JSON file?
    • Why does my JSON file look messy when I open it?

TL;DR Summary

  • Learning how to open a JSON file is simple since JSON is just plain text.
  • On Windows, use Notepad for a quick look or VS Code for a cleaner view.
  • On Mac, TextEdit works for basic viewing, while VS Code adds syntax highlighting.
  • No software needed? Online tools let you open a JSON file directly in your browser.
  • For frequent editing, code editors like VS Code or Sublime Text are your best bet.

💡 Did You Know?

JSON was created by Douglas Crockford in 2001 as a lightweight, language-independent format for exchanging data and is now used in almost all programming languages.

What Is a JSON File?

01@2

Before understanding JSON files, let’s know the definition of JSON.

JSON (JavaScript Object Notation) is a light-weight data format that stores and transmits data objects in human-readable text. It organizes and structures the data using key-value pairs and arrays, making it easier for both humans and machines to comprehend.

A JSON file is a collection of data and information in a simple text format, allowing users to view the data as objects. Objects have properties attached to them, and these properties contain the information in the form of an array of objects. 

The JSON files are used extensively to transfer data between applications, APIs, and servers, establishing a strong connectivity among different components in the software architecture. These files don’t consume excessive memory and storage, are easier to read and write, and require minimal resources. This simplicity and broad compatibility of JSON files make them an essential element for developing modern age apps.

Vital Information:

We use JavaScript as our primary language to explain the JSON examples below. Developers can use any programming language, such as Python, Java, C#, or PHP, to work with JSON.

Also Read: Handling JSON Datetime Between Python and JavaScript

Go beyond the basics with HCL GUVI’s Software and AI Engineer Course; master React, Node.js, REST APIs, and MongoDB while building real full-stack applications. Learn DSA, System Design, and AI-integrated development from industry mentors, with placement support from 1000+ hiring partners. Enroll today and build the skills top tech companies actually hire for!

How to Create a JSON File

02@2
const fs = require('fs').promises;

const data = {

    name: "Abhishek",

    age: 25,

    skills: ["JavaScript", "React", "Node.js"]

};

async function createJSONFile() {

    try {

        await fs.writeFile('data.json', JSON.stringify(data, null, 4));

        console.log("JSON file created successfully!");

    } catch (err) {

        console.error("Error writing file:", err);

    }

}

createJSONFile();

Explanation:

  • Here, we use the fs (file system) module, a built-in Node.js library, to let JavaScript interact with the computer’s file system.
  • const fs = require(‘fs’).promises. This line loads the fs module with promises in Node.js, allowing us to use async/await instead of callbacks.   
  • Now, in this case, we have created a data variable and initialized it with an object that contains the following information in key-value pairs, such as “name”: “Abhishek”, “age”: 25, and “skills”: [“JavaScript”, “React”, “Node.js”].   
  • But remember that data can be stored in a JSON file as text only, which is why we used JSON.stringify(data, null, 4) method to convert the data object into a JSON-formatted string. Inside this function, the null parameter is used to modify keys, but since we don’t want that, we set it to null. The last parameter is set to 4 for indentation, making the JSON file readable instead of a long line.
  • You can see the createJSONFile() function, which is used to perform an asynchronous operation to create a new JSON file, data.json() and write the JSON string into it. Here, the await keyword is used to tell the JS code to wait for the create operation to complete before moving on. Additionally, errors are handled using a try/catch block. At last, we have finally invoked the function.

Explore our free resources to delve deep into the concepts of JavaScript: JS eBook

How to Open a JSON File

03@2

1. Opening a JSON File on Windows:

Opening a JSON file on Windows is a simple task. You just have to right-click the file, choose the “Open with” option, and then select either Notepad or VS Code. Choosing Notepad to open the JSON file will give you plain text, whereas VS Code shows you the data format in colored syntax, making it easier to understand the information structure.

2. Opening JSON File on Mac:

Similar to Windows, when you open a JSON file on macOS, you have to right-click it and select the “Open With” option. The only difference is that instead of Notepad, there will be a TextEdit app to view JSON as plain text, while VS Code is for better readability.

3. Opening JSON File Online:

To open a JSON file online, you can visit websites like json-editor-online. You only need to upload your JSON file or paste the content structure, and the platform will display it in a well-structured and easy-to-read format. In these kinds of sites, along with opening and editing the JSON files, you can also validate them.

Note: You can also use a browser extension like JSON Formatter for Chrome — it automatically turns raw JSON into a clean, readable tree view whenever you open a .json file or API response directly in your browser.

4. Opening JSON File in Code Editors:

Multiple code editors, such as VS Code, Atom, Sublime Text, and more, help users open JSON files. These powerful tools highlight the syntax and elements within the JSON file interactively and colorfully, automatically indent the data, and enable navigation through nested structures. Opening JSON files in code editors is beneficial for developers who frequently read or edit them.

GUVI Ad

Which Tool Should You Use to Open a JSON File?

Choosing the right tool to open a JSON file depends on your device and what you plan to do with the data.

PlatformToolBest ForView Type
WindowsNotepadQuick, no-setup viewingPlain text
WindowsVS CodeReading and editing with clarityColored syntax
MacTextEditQuick, no-setup viewingPlain text
MacVS CodeReading and editing with clarityColored syntax
OnlineJSON editor websitesViewing without installing anythingStructured + validated
Code EditorsVS Code, Atom, Sublime TextFrequent editing, nested JSON structuresInteractive, color-coded

Important Note:

  • If you just need to glance at a JSON file once, Notepad or TextEdit will do.
  • If you’re a developer working with JSON regularly, a code editor like VS Code is worth the extra step — it saves time on formatting and catches errors early.

How to Read a JSON File

04@2x
const fs = require('fs');

// Read JSON file

fs.readFile('data.json', 'utf-8', (err, jsonString) => {

    if (err) {

        console.log("File read failed:", err);

        return;

    }

    try {

        const data = JSON.parse(jsonString);      // Convert JSON string to JS object

        console.log(data);

        console.log("Name:", data.name);

        console.log("Skills:", data.skills);

    } catch (err) {

        console.log("Error parsing JSON:", err);

    }

});

Explanation:

  • We have imported the fs (File System) module as it allows us to read, write, and manage files. Inside this module, readFile is a function that we have accessed as fs.readFile. It is an asynchronous function that helps in reading the content of the JSON file (data.json) without blocking the main JS thread, and returns the content as a text string through a callback ( (err, jsonString) => { … } ).
  • In this code statement, ‘ fs.readFile(‘data.json’, ‘utf-8’, (err, jsonString) => { … }) ‘, we are calling the function and asking Node.js to read the data.json file. The second parameter ‘utf-8’ specifies the backend to decode the file bytes into a string using the UTF-8 encoding. Without the UTF-8 encoding, we would get a raw binary form of data.
  • The third parameter is the callback function, which has two parameters: err (to detect errors) and jsonString (to hold the JSON content as a text string).
  • Now, inside this callback, we first apply an if condition to check for reading errors, such as when the file doesn’t exist or lacks permissions. Then we have implemented a try…catch block for handling JSON parsing.
  • Here, we have converted the JSON string to JS object data. If any error occurs in the JSON file, such as missing commas, incorrect data types, or incorrect quotes, we wrap the code in a try/catch block. If parsing succeeds, we can print the data object to the console; if it fails, we can log an error message.
GUVI Ad

How to Edit a JSON File

05@2x
const fs = require('fs');

// Read JSON file

fs.readFile('data.json', 'utf-8', (err, jsonString) => {

    if (err) {

        console.log("File read failed:", err);

        return;

    }

    try {

        const data = JSON.parse(jsonString);   // Convert JSON string to JS object

        // Modify the object

        data.age = 26;

        data.skills.push("Node.js");

        // Save updated object back to JSON file

        fs.writeFile('data.json', JSON.stringify(data, null, 4), (err) => {

            if (err) throw err;

            console.log("JSON file updated successfully!");

        });

    } catch (err) {

        console.log("Error parsing JSON:", err);

    }

});

Explanation:

  • To modify the object in memory in this example, we have used the push method (data.skills).push(“Node.js”) for adding the property to the existing skills array, and also directly updated the age property by specifying a new number (data.age = 26).
  • Once the object is modified, you need to save the changes back to the file. This is done with fs.writeFile(‘data.json’, JSON.stringify(data, null, 4), (err) => { … }).

Best Practices for Working with JSON Files

The following are the best practices while working with the JSON files:

  • Validate JSON – Check formatting before parsing.
  • Use UTF-8 encoding – Ensures readable text, not raw bytes.
  • Handle errors – Always catch parsing and file I/O errors.
  • Stringify with indentation – Makes JSON human-readable.
  • Avoid unsupported data – Only use strings, numbers, booleans, arrays, objects, or null.

Conclusion

Today, we learned how to create, read, and edit JSON files in JavaScript; understood the difference between JSON as a string in files and JavaScript objects in memory; explored error handling and common JSON mistakes; and discussed modern async/await methods and best practices for working with JSON efficiently and safely.

FAQs

1. Can I open a JSON file with Notepad?

Yes. Right-click the file, choose “Open with,” and select Notepad. It’ll show as plain text.

2. What program opens JSON files by default?

There’s no default program on most systems. You choose how to open a JSON file — usually a text editor or browser.

3. Can I open a JSON file in Excel?

Yes, but you’ll need to import it through Excel’s “Get Data” or Power Query feature — it won’t open directly like a text file.

4. Do I need special software to open a JSON file?

No. Since JSON is plain text, any text editor or browser can open it. Special tools just make it easier to read.

5. Why does my JSON file look messy when I open it?

It’s likely “minified” (no spacing). Use a code editor or online JSON formatter to make it readable.

Success Stories

Did you enjoy this article?

Learn with HCL GUVI

Schedule 1:1 free counselling

Similar Articles

Loading...
Get in Touch
Chat on Whatsapp
Request Callback
Share logo Copy link
Table of contents Table of contents
Table of contents Articles
Close button

  1. TL;DR Summary
  2. What Is a JSON File?
  3. How to Create a JSON File
  4. How to Open a JSON File
    • Opening a JSON File on Windows:
    • Opening JSON File on Mac:
    • Opening JSON File Online:
    • Opening JSON File in Code Editors:
  5. Which Tool Should You Use to Open a JSON File?
  6. How to Read a JSON File
  7. How to Edit a JSON File
  8. Best Practices for Working with JSON Files
  9. Conclusion
  10. FAQs
    • Can I open a JSON file with Notepad?
    • What program opens JSON files by default?
    • Can I open a JSON file in Excel?
    • Do I need special software to open a JSON file?
    • Why does my JSON file look messy when I open it?