What Goes Inside a JSON File
A JSON file holds exactly one JSON value, usually an object { } or an array [ ]. Keys and text use double quotes, and there are no comments or trailing commas. A minimal example to start from:
{
"name": "Emily Clark",
"email": "emily@example.com",
"age": 30,
"active": true,
"tags": ["admin", "editor"],
"address": {
"city": "London",
"zip": "E1 6AN"
}
}Not sure about the rules? JSON Syntax Rules lists them, and the JSON Cheat Sheet has them on one page.
Windows: Notepad
- Open Notepad and paste or type your JSON.
- Choose File → Save as.
- Set Save as type to All files (*.*), so Windows does not add .txt.
- Type a name ending in
.json, for exampledata.json. - Leave Encoding on UTF-8 (the default in Windows 11), not "UTF-8 with BOM", and click Save.
Windows hides known file extensions, so a file that looks like data.json may really be data.json.txt. In File Explorer, turn on View → Show → File name extensions to check.
Mac: TextEdit
- Open TextEdit and choose Format → Make Plain Text (rich text files are not JSON).
- Turn off Edit → Substitutions → Smart Quotes, or straight quotes
"turn into curly ones that break JSON. - Paste your JSON, then File → Save, name it
data.json, and choose UTF-8. - If you see "If no extension is provided, use .txt", untick it. If asked, choose Use .json.
VS Code (Any System)
- File → New File, then save it as
data.json. VS Code switches to JSON mode from the name. - Type your JSON. Errors are underlined in red as you type.
- Press Shift + Alt + F (Mac: Shift + Option + F) to format it.
VS Code saves as UTF-8 without a BOM by default, which every JSON parser reads.
Online, Without Installing Anything
- Open the JSON Formatter and paste or type your data.
- Click Format. Common mistakes like trailing commas and single quotes are fixed for you.
- Click Download to save a ready
.jsonfile.
Need sample data instead of typing it? The JSON Generator creates realistic test records, and there are ready-made free JSON datasets. Have a spreadsheet? Turn it into a JSON file with CSV to JSON or Excel to JSON.
Python
import json
data = {"name": "Emily Clark", "age": 30, "tags": ["admin", "editor"]}
with open("data.json", "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, ensure_ascii=False)encoding="utf-8" matters on Windows, where Python otherwise may use an older code page. ensure_ascii=False keeps characters like ü or 日本 readable instead of ü. More in JSON in Python.
JavaScript (Node.js)
import { writeFileSync } from 'node:fs'
const data = { name: 'Emily Clark', age: 30, tags: ['admin', 'editor'] }
writeFileSync('data.json', JSON.stringify(data, null, 2) + '\n', 'utf8')Reading it back is covered in Read a JSON File in Node.js. In a browser, you can offer the same text as a download with a Blob of type application/json.
PowerShell: Watch the Encoding
This is the most common way to create a JSON file that looks fine but will not load. We tested three ways of writing the same JSON in Windows PowerShell 5.1:
| Command | File starts with | Python json.load | Node.js JSON.parse |
|---|---|---|---|
$json > data.json | UTF-16 (FF FE) | ❌ UnicodeDecodeError | ❌ Unexpected token |
Set-Content -Encoding UTF8 | UTF-8 BOM (EF BB BF) | ❌ Unexpected UTF-8 BOM | ❌ Unexpected token |
[IO.File]::WriteAllText(...) | Plain UTF-8 | ✅ Works | ✅ Works |
$data = @{ name = 'Emily Clark'; age = 30; tags = @('admin', 'editor') }
$json = $data | ConvertTo-Json -Depth 10
[IO.File]::WriteAllText("$PWD\data.json", $json) # UTF-8 without BOMPowerShell 7 writes UTF-8 without a BOM by default, so Set-Content is fine there. More PowerShell tips in JSON in PowerShell.
Check the File Before You Use It
Open the file in the JSON Validator (drop it on the box). It shows the line and column of any error. If the first line is marked even though it looks right, the file probably has a BOM or the wrong encoding: save it again as plain UTF-8.
Common Mistakes
| Problem | Sign | Fix |
|---|---|---|
Hidden .txt extension | Programs say the file is not found, or open it as text | Show file extensions and rename to .json |
| Smart (curly) quotes | “name” instead of "name", "Expected property name or '}'" | Turn off smart quotes; do not write JSON in Word |
| BOM or UTF-16 | Error at line 1, column 1 | Save as UTF-8 (without BOM) |
| Trailing comma or comments | "Expected double-quoted property name" | Remove them, or let JSON Repair do it |
| Two objects in one file | "Unexpected non-whitespace character after JSON" | Wrap them in an array [ ], or use JSON Lines |
Frequently Asked Questions
How do I create a JSON file in Notepad?
Type or paste your JSON, choose File → Save as, set Save as type to All files, enter a name like data.json and keep the encoding on UTF-8. Then check the file in a JSON validator.
Why does my JSON file end in .txt?
Windows hides file extensions and Notepad may add .txt. Turn on File name extensions in File Explorer and rename the file so it ends in .json.
Why does my JSON file fail at line 1, column 1?
The file was probably saved with a UTF-8 BOM or as UTF-16, which Windows PowerShell 5.1 does with > and Set-Content. Save it again as plain UTF-8 without a BOM.
Can I create a JSON file online?
Yes. Paste or type your data into an online JSON formatter, click Format to check and fix it, then click Download to save a .json file.