How to Save a JSON File

You can save a JSON file by putting valid JSON text in a plain-text editor, saving it with a .json filename, and choosing UTF-8 encoding when your editor offers that option. The important parts are using JSON’s required syntax, avoiding rich-text formatting, and confirming that the file really ends in .json rather than .txt.

What a JSON File Is

JSON stands for JavaScript Object Notation. It is a plain-text format used for configuration files, API responses, application data, and data exchange between programs.

A JSON document can contain:

  • An object, enclosed in curly braces: { }
  • An array, enclosed in square brackets: [ ]
  • Strings in double quotes
  • Numbers
  • true, false, and null

Here is a small valid JSON file:

{
  "name": "Avery",
  "active": true,
  "projects": ["website", "api"]
}

JSON has strict rules. In particular:

  • Property names must use double quotes.
  • Text values must use double quotes.
  • Items need commas between them.
  • The final item in an object or array cannot have a trailing comma.
  • Curly “smart quotes” from word processors are not valid JSON.

A .json extension names the file, but valid JSON syntax is what makes its contents usable by an application.

How to Save a JSON File

Choose the method that matches where your JSON currently is.

Starting Point Best Method What You Need to Do
You are typing or pasting JSON Plain-text editor Save the text as filename.json
You have an API response in a browser or request client Copy the response body Paste it into a new plain-text file and save it
Your program has data in memory Code Serialize the data and write it to a .json file
You received a JSON file with the wrong extension File manager Rename the file so it ends in .json, then validate it

Step 1: Put the Data in a Plain-Text Editor

  1. Open a plain-text editor or code editor.
  2. Create a new file.
  3. Type or paste the JSON content.
  4. Check that the file begins and ends correctly: objects use { }, while arrays use [ ].

For example, paste this into the new file:

{
  "service": "inventory-api",
  "port": 8080,
  "debug": false
}

Use an editor intended for plain text. Code editors are especially helpful because they can color JSON syntax and point out missing commas or unmatched braces.

Do not use a word processor unless it can save plain text without formatting. Rich-text editors can add smart quotes, hidden formatting, or other characters that make a JSON parser fail.

Step 2: Check the JSON Before Saving

  1. Confirm that every key and string value uses straight double quotes: ".
  2. Make sure commas appear between properties.
  3. Remove any comma after the last property.
  4. Match every opening { or [ with a closing } or ].

This is invalid because it has a trailing comma:

{
  "environment": "development",
}

This is valid:

{
  "environment": "development"
}

A JSON validator or your editor’s JSON support can catch structural mistakes before the file reaches your application. Validation is particularly useful after copying a long API response or editing a configuration file by hand.

Step 3: Save It With the .json Extension

  1. In the editor, choose File > Save As.
  2. Pick the folder where the application, script, or project expects the file.
  3. Enter a name ending in .json, such as config.json, response.json, or data.json.
  4. Select UTF-8 encoding if the Save As window provides an encoding choice.
  5. Save the file.

UTF-8 is the common encoding for JSON files and safely supports ordinary English text as well as Unicode characters such as accented names and non-Latin scripts. The exact encoding control varies by editor; look in that editor’s save or encoding options.

If the editor automatically appends .txt, your finished name may become config.json.txt. Check the file name in your file manager after saving.

Step 4: Reopen and Validate the Finished File

  1. Close the file.
  2. Open it again in a plain-text editor.
  3. Confirm the name ends in .json.
  4. Run a JSON validation feature or load the file in the program that needs it.

If the file opens as ordinary text, that is normal. JSON is text. What matters is that software can parse its structure successfully.

Saving JSON on Windows, macOS, and Linux

Save valid JSON as a plain-text file whose name ends in .json, using UTF-8 when an encoding selector is available.

Save JSON in Notepad on Windows

You can create and save JSON in Notepad.

  1. Open Notepad and paste or type valid JSON.
  2. Choose File > Save As.
  3. Name the file with .json at the end, such as settings.json.
  4. Choose UTF-8 encoding if Notepad shows an encoding selector.
  5. Save the file, then check in File Explorer that it does not end in .txt.

Windows may hide known file extensions. If a file appears to be named settings.json but software cannot open it as JSON, inspect its full name in File Explorer. It may actually be settings.json.txt.

For project files, a code editor is usually more convenient than Notepad because it can format and validate JSON as you work.

Save JSON on macOS

On macOS, save JSON from a plain-text editor or code editor. If you use TextEdit, make sure the document is plain text rather than rich text before pasting JSON.

Save the file through File > Save As, use a name such as data.json, and select UTF-8 if the editor shows encoding options. If macOS or the app changes the extension, rename the finished file in Finder so its name ends in .json.

Avoid smart quotes. JSON requires normal straight quotation marks around keys and string values.

Save JSON on Linux

On Linux, use a text editor or code editor, save the document as filename.json, and keep it in the project directory or another location your program can access.

The operating system does not determine whether a file is valid JSON. The extension helps people and tools identify the format, but the JSON syntax and text encoding still need to be correct.

How to Save JSON Responses Without Python

You do not need Python to save a JSON API response. Any API request client, browser developer tool, or command-line tool that displays the response body can be used.

  1. Send the API request.
  2. Locate the response body rather than the request headers.
  3. Copy the complete JSON response.
  4. Paste it into a new plain-text file.
  5. Save it as a .json file using UTF-8 encoding when available.
  6. Validate the saved file before using it as fixture data, test input, or a configuration sample.

Be careful not to save only a displayed preview if the tool truncates large responses. Look for an option to view the complete response or download/export the response body before copying it.

I use an API request client for this because it separates the response body from headers, status details, and request metadata.

When a response includes secrets, such as access tokens, session cookies, API keys, email addresses, or customer data, do not commit the saved file to source control. Store sanitized test data instead, or keep the file outside the repository.

Saving JSON From Code

Programs should serialize data rather than assembling JSON with string concatenation. A JSON library handles quotes, escaping, arrays, booleans, and null values correctly.

Save JSON With Python

Python includes the json module. This example saves a dictionary to settings.json:

import json
settings = {
    "theme": "dark",
    "notifications": True,
    "recent_projects": ["api", "dashboard"]
}
with open("settings.json", "w", encoding="utf-8") as file:
    json.dump(settings, file, indent=4)

The indent=4 setting writes readable JSON with 4 spaces per indentation level. You can confirm or change that value directly in the json.dump() call; omit indent when you need a compact file instead.

The with block closes the file after writing, including if an error occurs while the program is running.

Save JSON With JavaScript

In Node.js, convert the object with JSON.stringify() and write the resulting text to a file:

import { writeFile } from "node:fs/promises";
const settings = {
  theme: "dark",
  notifications: true,
  recentProjects: ["api", "dashboard"]
};
await writeFile(
  "settings.json",
  JSON.stringify(settings, null, 2),
  "utf8"
);

The final argument ensures UTF-8 output. The null, 2 arguments format the output with indentation so people can read and edit the file more easily.

Save JSON Files Safely

JSON files are often configuration or data files, so an accidental overwrite can break an application or erase useful data.

Use these habits when editing them:

  • Keep the original file until the replacement has been validated.
  • Save a copy under a different name before making large manual changes.
  • Use source control for JSON configuration that belongs in a software project.
  • Do not commit credentials, tokens, private keys, or production data.
  • Validate the JSON after editing, especially after resolving merge conflicts.
  • Keep a consistent file name and location when another program loads the file automatically.

If an application reads config.json, do not casually rename the file to config-final.json or move it elsewhere. The JSON may be valid, but the application will fail if it cannot find the expected path.

Common JSON Saving Problems

The File Is Saved as .json.txt

A file can end up as .json.txt when a text editor adds .txt automatically. Rename the file so the full name ends in .json, then reopen it and validate the content.

The File Looks Correct but Will Not Parse

Look for smart quotes, a missing comma, an extra comma, unquoted property names, or mismatched braces. A validator will usually identify the line where parsing stops.

The File Contains HTML Instead of JSON

An API response file can contain HTML rather than JSON when a request fails and returns an HTML error page, login page, or proxy message. Check the first characters of the file. JSON usually begins with {, [, ", a number, true, false, or null; an HTML response often begins with <.

The JSON Is One Long Line

One-line JSON is still valid. Formatting affects readability, not validity. Use an editor’s format-document feature or save programmatically with indentation when people need to review the file.

Frequently Asked Questions

What is the best extension for a local JSON file?

Use the .json extension, such as data.json or config.json. It helps editors, operating systems, and development tools recognize the file format, though the content must still follow valid JSON syntax.

Can I store JSON files on a laptop?

Yes. A JSON file is an ordinary text file, so you can store it anywhere you can store documents or project files. Put application configuration in the location the application expects, and keep sensitive JSON files out of shared folders and public repositories.

How do I create a JSON file from scratch?

Open a plain-text editor, write a valid JSON object or array, then choose File > Save As and name the file with a .json extension. Select UTF-8 when the editor provides an encoding option, then validate the result before using it.

How do I save a JSON file from Notepad?

Paste valid JSON into Notepad, choose File > Save As, and name the file something like data.json. Save with UTF-8 encoding if shown, then confirm in File Explorer that the actual file name does not end in .json.txt.

Where should I save a JSON request or response?

Save it in a project folder when it is test data, an API fixture, or documentation for that project. Remove secrets before saving a response, and avoid committing private response data, tokens, or credentials to version control.

Does JSON need to be formatted with indentation?

No. JSON can be compact on one line or formatted across many lines. When writing JSON in Python, indent=4 produces a readable layout with 4 spaces per level; compact JSON is useful when file size matters more than manual readability.