DevToolBoxฟรี
บล็อก

วิธีเปิดไฟล์ JSON: คู่มือฉบับสมบูรณ์สำหรับนักพัฒนา

9 นาทีในการอ่านโดย DevToolBox

If you have ever downloaded an API response, received a configuration file, or exported data from a web application, you have probably encountered a .json file. JSON (JavaScript Object Notation) is the most widely used data format on the web, but how to open a JSON file depends on what you want to do with it: simply view it, edit it, validate it, or parse it programmatically. This comprehensive guide covers every method available for opening and viewing JSON files, from code editors and command-line tools to online formatters and programming languages. Whether you are a beginner wondering what program opens JSON files or an experienced developer looking for the fastest workflow, you will find the right approach here.

Open and format JSON files instantly with our free JSON Formatter.

What Is a JSON File?

A JSON file is a plain-text file that stores data in JavaScript Object Notation format. It uses key-value pairs and ordered lists to represent structured data. JSON files typically have the .json extension and are encoded in UTF-8. They are used everywhere in modern software: REST API responses, application configuration (like package.json or tsconfig.json), database exports, and data interchange between services.

Because JSON is plain text, you can open it with any text editor. However, raw JSON is often minified (stripped of whitespace) or deeply nested, making it difficult to read without proper formatting. That is why developers use specialized tools to view JSON files with syntax highlighting, indentation, collapsible nodes, and validation.

Method 1: Open JSON Files in VS Code

Visual Studio Code is the most popular editor for working with JSON files. It provides built-in JSON support with syntax highlighting, auto-formatting, schema validation, and IntelliSense. To open a JSON file in VS Code:

  1. Launch VS Code and press Ctrl+O (Windows/Linux) or Cmd+O (macOS) to open the file dialog.
  2. Navigate to your .json file and select it. VS Code automatically detects the JSON language mode.
  3. To format the JSON, right-click in the editor and choose Format Document, or press Shift+Alt+F (Windows) / Shift+Option+F (macOS). This prettifies minified JSON instantly.
  4. For large JSON files, use the Outline panel (View > Outline) to navigate the structure, or install the JSON Viewer extension for a tree-view sidebar.

VS Code also validates JSON automatically. If your file has syntax errors like trailing commas, missing quotes, or mismatched brackets, squiggly red underlines appear immediately. Hover over the error for a detailed description. For JSON files that follow a schema (like package.json), VS Code provides IntelliSense suggestions and type checking.

Method 2: Open JSON Files in a Web Browser

Every modern web browser can display JSON files. Simply drag and drop a .json file onto an open browser window, or use File > Open File. Firefox has the best built-in JSON viewer: it automatically formats the data with collapsible sections, a search bar, and the ability to switch between raw and formatted views.

Chrome displays raw JSON by default, but you can install browser extensions like JSON Viewer or JSONVue from the Chrome Web Store to get formatted output with syntax highlighting and tree navigation. For a quick one-off viewing without installing anything, paste your JSON into our online tool:

View and format JSON in your browser with our JSON Viewer tool.

Method 3: Open JSON Files in the Terminal (cat, jq, python)

Command-line tools are the fastest way to inspect JSON files on any operating system. Here are the most common approaches:

cat / less: The simplest method. Run cat file.json to dump the contents to your terminal, or less file.json for paginated output. This shows the raw text without formatting, which works for small files.

# Pretty-print JSON with cat (raw) or less (paginated)
cat data.json
less data.json

# Pretty-print with jq (recommended)
jq . data.json

# Extract a specific field
jq '.users[0].name' data.json

# Pretty-print with Python
python3 -m json.tool data.json

jq: The Swiss Army knife for JSON on the command line. Run jq . file.json to pretty-print the entire file with color-coded syntax highlighting. You can also filter and transform data: jq '.users[0].name' file.json extracts a specific value. Install jq via brew install jq (macOS), apt install jq (Ubuntu), or choco install jq (Windows).

python -m json.tool: Python ships with a built-in JSON formatter. Run python3 -m json.tool file.json to pretty-print any JSON file. This also validates the JSON and reports syntax errors with line numbers. No additional installation required if Python is already on your system.

PowerShell (Windows): Use Get-Content file.json | ConvertFrom-Json | ConvertTo-Json -Depth 10 to read and re-format JSON. The -Depth parameter controls how many levels of nesting to preserve.

Method 4: Open JSON Files in Notepad++ or Sublime Text

Notepad++ (Windows) recognizes JSON files and provides syntax highlighting out of the box. For pretty-printing, install the JSTool plugin via the Plugin Manager, then use Plugins > JSTool > JSFormat to indent and format the JSON. Notepad++ handles large files efficiently and supports find-and-replace with regex.

Sublime Text (cross-platform) also has excellent JSON support. Open any .json file and use Ctrl+Shift+P > Pretty Print (JSON) to format the document. Sublime Text is especially fast with large JSON files (hundreds of megabytes) compared to other editors.

Method 5: Open JSON Files with Online Tools

Online JSON tools are the quickest option when you need to view, format, or validate JSON without installing any software. Our JSON Formatter tool lets you paste or upload a JSON file, then instantly see a formatted, syntax-highlighted, and validated result:

Try our free online JSON Formatter and Validator.

Online tools are especially useful for: sharing formatted JSON with colleagues via a link, validating JSON before sending it to an API, converting between minified and prettified formats, and checking for syntax errors in configuration files. Our toolset also includes a dedicated JSON Viewer with a tree-view interface for exploring deeply nested structures:

Explore JSON structures with our interactive JSON Viewer.

Method 6: Open JSON Files with Python

Python's built-in json module makes it trivial to read, parse, and display JSON files programmatically. This is the go-to approach when you need to process JSON data in scripts or applications:

import json

# Read and parse a JSON file
with open('data.json', 'r', encoding='utf-8') as f:
    data = json.load(f)

# Access values
print(data['name'])
print(data['users'][0]['email'])

# Pretty-print the entire structure
print(json.dumps(data, indent=2, ensure_ascii=False))

# Validate JSON from a string
try:
    parsed = json.loads(json_string)
    print("Valid JSON")
except json.JSONDecodeError as e:
    print(f"Invalid JSON: {e}")

The json.load() function reads a JSON file and returns a Python dictionary (or list). You can then access any value using standard Python dictionary syntax. The json.dumps() function with indent=2 converts the data back to a pretty-printed JSON string for display or logging.

Method 7: Open JSON Files with Node.js

Node.js provides multiple ways to read and parse JSON files. The simplest is using require() or the built-in fs module:

// Method 1: require (CommonJS)
const data = require('./data.json');
console.log(data.name);

// Method 2: fs.readFileSync
const fs = require('fs');
const raw = fs.readFileSync('data.json', 'utf-8');
const parsed = JSON.parse(raw);

// Pretty-print
console.log(JSON.stringify(parsed, null, 2));

// Method 3: fs/promises (async, ESM)
import { readFile } from 'fs/promises';
const content = await readFile('data.json', 'utf-8');
const json = JSON.parse(content);

// Validate JSON
try {
  JSON.parse(rawString);
  console.log('Valid JSON');
} catch (e) {
  console.error('Invalid JSON:', e.message);
}

For modern ESM projects, use import with the assert syntax or read the file with fs/promises. Node.js automatically parses JSON when you use JSON.parse(), and you can format the output with JSON.stringify(data, null, 2) for pretty-printing.

How to Validate a JSON File

Invalid JSON is a common source of bugs. A single trailing comma, unquoted key, or mismatched bracket can break an entire configuration. Here are reliable ways to validate JSON:

  1. Online validator: Paste your JSON into our JSON Validator for instant error detection with line numbers and descriptive messages.
  2. VS Code: Red underlines appear automatically for JSON syntax errors.
  3. jq: Run jq . file.json. If the JSON is invalid, jq prints an error with the exact location.
  4. python: Run python3 -m json.tool file.json. Invalid JSON produces a json.decoder.JSONDecodeError with the line and column number.
  5. Node.js: JSON.parse() throws a SyntaxError with a position indicator if the JSON is malformed.

Validate your JSON files instantly with our JSON Validator tool.

Opening Large JSON Files (100MB+)

Standard text editors struggle with very large JSON files. For files over 100MB, use these specialized approaches:

  1. jq (streaming mode): Use jq --stream to process large JSON files without loading the entire file into memory. This is ideal for extracting specific fields from multi-gigabyte files.
  2. fx: An interactive JSON viewer for the terminal. Install with npm install -g fx and run fx file.json to browse the structure interactively with search, filtering, and collapsing.
  3. Python ijson: The ijson library provides an iterative/streaming JSON parser for Python. Install with pip install ijson and use it to process JSON elements one at a time without loading the entire file.
  4. Sublime Text: Can handle files up to several hundred MB with reasonable performance, unlike VS Code which may become unresponsive.

Frequently Asked Questions

What program opens JSON files?

Any text editor can open JSON files because JSON is plain text. The best options are VS Code (with built-in formatting and validation), Notepad++ (Windows), Sublime Text, or online tools like the DevToolBox JSON Formatter. For quick command-line viewing, use jq or python -m json.tool. Web browsers can also display JSON files directly, with Firefox providing the best built-in formatting.

How to view a JSON file?

To view a JSON file with proper formatting, open it in VS Code and press Shift+Alt+F to format, use jq on the command line with jq . file.json for color-coded output, drag it into Firefox for automatic tree-view formatting, or paste the contents into an online JSON formatter like the one at viadreams.cc/en/tools/json-formatter. For programmatic viewing, use Python json.load() or Node.js JSON.parse() to parse and display the data.

Can I open a JSON file in Excel?

Yes, Excel can import JSON files using Power Query. In Excel, go to Data > Get Data > From File > From JSON, then select your file. Excel will open the Power Query Editor where you can expand nested objects and arrays into columns and rows. This is useful for analyzing JSON data in a spreadsheet format. For simple flat JSON arrays, you can also convert JSON to CSV first using a tool like our CSV-JSON converter, then open the CSV in Excel.

How do I open a JSON file on my phone?

On Android, use a text editor app like QuickEdit or Acode. On iOS, use Textastic or Jayson (a dedicated JSON viewer). You can also open JSON files in your mobile browser by navigating to an online JSON formatter tool and pasting or uploading the file content. Cloud-based editors like VS Code for Web (vscode.dev) work in mobile browsers as well.

Why does my JSON file show as one long line?

Your JSON file is minified, meaning all whitespace has been removed to reduce file size. This is common for JSON served by APIs or included in production builds. To make it readable, format it using any of the methods described above: VS Code Format Document (Shift+Alt+F), jq . file.json on the command line, or paste it into an online JSON formatter. The data is identical; only the visual presentation changes.

Opening and viewing JSON files is straightforward once you know the right tool for your situation. Use VS Code or Sublime Text for daily editing, jq for command-line workflows, your web browser for quick viewing, and online tools when you need a no-install solution. For programmatic access, Python and Node.js both provide excellent built-in JSON support. Whatever your use case, the key is choosing a tool that provides proper formatting, syntax highlighting, and validation so you can work with JSON data efficiently.

Format and validate your JSON files with our free online JSON Formatter.

Related Developer Tools and Guides

𝕏 Twitterin LinkedIn
บทความนี้มีประโยชน์ไหม?

อัปเดตข่าวสาร

รับเคล็ดลับการพัฒนาและเครื่องมือใหม่ทุกสัปดาห์

ไม่มีสแปม ยกเลิกได้ตลอดเวลา

ลองเครื่องมือที่เกี่ยวข้อง

{ }JSON Formatter🌳JSON Viewer / TreeJSON Validator

บทความที่เกี่ยวข้อง

JSON Formatter & Validator: จัดรูปแบบและตรวจสอบ JSON ออนไลน์

เครื่องมือจัดรูปแบบและตรวจสอบ JSON ฟรี จัดรูปแบบ JSON หาข้อผิดพลาดทางไวยากรณ์ พร้อมตัวอย่างโค้ด

JSON Parse Error: Unexpected Token — วิธีค้นหาและแก้ไข

แก้ไขข้อผิดพลาดการ parse JSON ทีละขั้นตอน

JSON vs YAML vs TOML: ควรใช้รูปแบบ Config แบบไหน?

เปรียบเทียบรูปแบบการกำหนดค่า JSON, YAML และ TOML