What is a JSON File?

Complete guide to understanding and working with .json files

Published: January 2025 • 11 min read

A JSON file is a text file that stores data in JSON (JavaScript Object Notation) format. JSON files use the .json file extension and contain structured data that's both human-readable and machine-parsable.

If you've worked with configuration files like package.json in Node.js projects or tsconfig.json in TypeScript, you've already encountered JSON files. They're everywhere in modern software development, from storing application settings to exchanging data between systems.

Quick Definition: A JSON file is a plain text file with a .json extension that stores data in JavaScript Object Notation format. Learn more about what JSON is.

Anatomy of a JSON File

Let's look at what makes up a JSON file:

File Extension

JSON files always end with .json:

config.json
data.json
users.json
package.json

File Content

A typical JSON file contains structured data:

{
  "name": "My Application",
  "version": "1.0.0",
  "description": "A sample JSON file",
  "author": "John Doe",
  "dependencies": {
    "express": "^4.18.0",
    "mongodb": "^5.0.0"
  },
  "keywords": ["api", "server", "backend"]
}

This example shows a configuration file with application metadata and dependencies.

Text-Based Format

Key characteristics:

  • Plain Text: Can be opened and edited with any text editor
  • UTF-8 Encoding: Supports international characters
  • No Binary Data: Purely text-based, unlike images or executables
  • Version Control Friendly: Works great with Git and other VCS

What Are JSON Files Used For?

JSON files serve many purposes in software development:

1. Configuration Files

Store application settings and preferences:

// package.json
{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "start": "node server.js",
    "test": "jest"
  }
}

Examples: package.json, tsconfig.json, .eslintrc.json

2. Data Storage

Store structured data for applications:

// users.json
{
  "users": [
    {
      "id": 1,
      "name": "Alice",
      "email": "[email protected]"
    },
    {
      "id": 2,
      "name": "Bob",
      "email": "[email protected]"
    }
  ]
}

Used in NoSQL databases like MongoDB and for local data storage

3. API Data Exchange

Transfer data between client and server:

// API response saved as response.json
{
  "status": "success",
  "data": {
    "userId": 12345,
    "username": "johndoe"
  }
}

REST APIs commonly send and receive JSON files

4. Data Export/Import

Export data from one system to import into another:

  • Database backups and migrations
  • Analytics data exports
  • Settings backup and restore

5. Mock Data for Testing

Create test data for development:

Visit our sample JSON files page to download ready-to-use test data.

How to Create a JSON File

Creating a JSON file is simple. Here are different methods:

Method 1: Using a Text Editor

  1. 1.
    Open any text editor:

    Notepad (Windows), TextEdit (Mac), VS Code, Sublime Text, etc.

  2. 2.
    Type your JSON data:
    {
      "name": "John Doe",
      "age": 30,
      "email": "[email protected]"
    }
  3. 3.
    Save the file with .json extension:

    File → Save As → data.json

  4. 4.
    Set encoding to UTF-8:

    Important for international characters

Learn more in our How to Create JSON Files guide.

Method 2: Using Programming Languages

Create JSON files programmatically:

JavaScript/Node.js:

const fs = require('fs');
const data = { name: "John", age: 30 };
fs.writeFileSync('data.json', JSON.stringify(data, null, 2));

Python:

import json
data = {"name": "John", "age": 30}
with open('data.json', 'w') as f:
    json.dump(data, f, indent=2)

Method 3: Using Online Tools

Create and validate JSON online:

How to Open a JSON File

JSON files can be opened in multiple ways:

Text Editors

Open with any text editor:

  • • Notepad (Windows)
  • • TextEdit (Mac)
  • • VS Code
  • • Sublime Text
  • • Atom

Web Browsers

Drag and drop into browser:

  • • Chrome
  • • Firefox
  • • Safari
  • • Edge

Online Tools

Use our tools:

Programming Languages

Read programmatically:

  • • JavaScript (JSON.parse())
  • • Python (json.load())
  • • Java, C#, PHP, etc.

Read our detailed guide: How to Open and Read JSON Files

JSON File Structure

A JSON file must follow specific structure rules. Learn more about JSON syntax.

Valid JSON File Structure

{
  "version": "1.0.0",
  "name": "My App",
  "settings": {
    "theme": "dark",
    "language": "en"
  },
  "features": ["auth", "api", "database"],
  "isPublic": true,
  "maxUsers": 100,
  "contact": null
}

✓ Proper key-value pairs with double quotes

✓ Valid data types (string, number, boolean, null, object, array)

✓ No trailing commas

✓ Properly nested structures

Top-Level Structure

JSON files typically start with:

  • An Object: { ... } (most common)
  • An Array: [...] (less common but valid)

JSON File Best Practices

1.
Use Descriptive File Names: user-config.json is better than data.json
2.
Always Validate: Use a JSON validator before saving
3.
Format for Readability: Use proper indentation (2 or 4 spaces)
4.
Use UTF-8 Encoding: Ensures compatibility with all characters
5.
Keep Files Organized: Store related JSON files in dedicated folders
6.
Version Control: JSON files work great with Git - commit them!

Common JSON Files You'll Encounter

package.json

Node.js project configuration and dependencies

tsconfig.json

TypeScript compiler configuration

.eslintrc.json

ESLint linter configuration

composer.json

PHP dependency management

manifest.json

Web app and browser extension manifest

settings.json

VS Code and other app settings

Tools for Working with JSON Files

Related Tools & Resources

Summary

A JSON file is a text file with a .json extension that stores structured data in JSON format. JSON files are:

  • Human-readable and machine-parsable
  • Used for configuration, data storage, and API communication
  • Easy to create with any text editor
  • Supported by virtually every programming language

Next Steps: Learn how to create JSON files or download sample JSON files to get started.