Merge JSON files online

Merge multiple JSON files into a single file. Combine data from different sources quickly and easily.

Files

Click anywhere to select filesor drag and drop files here
Accepts JSON files (.json)

Trusted by over 40,000 every month

JSON Merge Features

Multiple File Merging
Combine any number of files into a single consolidated file
Lightning-Fast Performance
Merge even large files instantly with optimized processing
Streamlined File Merging
Efficiently combine multiple files into a unified dataset
SQL-Powered Merging
Use SQL queries for advanced merging with custom join conditions
AI-Powered Assistance
Describe your merging needs in plain English for complex scenarios
Export Merged Data
Save your combined results in various formats

JSON Merge Examples

Our tool automatically picks the best way to merge your JSON files. Here are some examples:

Deep Merge

When merging objects with similar structure:

File 1:

json
{
  "name": "John",
  "age": 30,
  "address": {
    "city": "New York",
    "zip": "10001"
  }
}

File 2:

json
{
  "age": 25,
  "address": {
    "street": "123 Main St",
    "city": "Boston"
  }
}

Result:

json
{
  "name": "John",
  "age": 25,
  "address": {
    "city": "Boston",
    "zip": "10001",
    "street": "123 Main St"
  }
}

Array Concatenation

When merging arrays of objects:

File 1:

json
[
  {"id": 1, "type": "fruit", "name": "apple"},
  {"id": 2, "type": "fruit", "name": "banana"}
]

File 2:

json
[
  {"id": 3, "type": "fruit", "name": "orange"},
  {"id": 4, "type": "fruit", "name": "grape"}
]

Result:

json
[
  {"id": 1, "type": "fruit", "name": "apple"},
  {"id": 2, "type": "fruit", "name": "banana"},
  {"id": 3, "type": "fruit", "name": "orange"}
]

JSONL (JSON Lines)

When merging line-by-line JSON records:

File 1:

json
{"id": 1, "name": "Alice"}
{"id": 2, "name": "Bob"}

File 2:

json
{"id": 3, "name": "Charlie"}

Result:

json
{"id": 1, "name": "Alice"}
{"id": 2, "name": "Bob"}
{"id": 3, "name": "Charlie"}

How to merge JSON files in Python

Here are three effective ways to merge multiple JSON files in Python using different libraries. Each approach has its own advantages depending on your specific needs and file sizes.

Merging JSON files with Pandas

Pandas provides a straightforward approach for merging files and works well for most common data tasks:

First, let's install pandas if you haven't already:

bash
pip install pandas

Now we can load your json files into dataframes:

python
import pandas as pd

Let's load your first file:

python
df1 = pd.read_json('path/to/file1.json')

And your second file:

python
df2 = pd.read_json('path/to/file2.json')

Great! Now we can merge the dataframes using the concat function:

python
merged_df = pd.concat([df1, df2], ignore_index=True)

Finally, let's save your newly merged data to a file:

python
merged_df.to_json('path/to/merged_file.json', orient='records')

Need to merge more than two files? No problem! Just add them to the list in the concat function:

python
merged_df = pd.concat([df1, df2, df3, df4], ignore_index=True)

Merging JSON files with DuckDB

DuckDB is an in-process SQL OLAP database that's perfect for larger files and analytical workloads:

Let's start by installing DuckDB for Python:

bash
pip install duckdb

Now we'll import the library and create a connection:

python
import duckdb
con = duckdb.connect()

Here's a simple DuckDB query that will merge your json files using UNION ALL:

python
query = """
COPY (
  SELECT * FROM 'path/to/file1.json'
  UNION ALL
  SELECT * FROM 'path/to/file2.json'
) TO 'path/to/merged_file.json' (FORMAT 'json')
"""

Just run this query to perform the merge:

python
con.execute(query)

Got more than two files? Simply add more UNION ALL statements like this:

python
query = """
COPY (
  SELECT * FROM 'path/to/file1.json'
  UNION ALL
  SELECT * FROM 'path/to/file2.json'
  UNION ALL
  SELECT * FROM 'path/to/file3.json'
) TO 'path/to/merged_file.json' (FORMAT 'json')
"""

What's great about DuckDB is that it's incredibly efficient for large files - it processes data in a columnar format and can handle files that don't fit in memory. Perfect for those bigger merging jobs!

Merging JSON files with ClickHouse

ClickHouse is a high-performance column-oriented database system that's excellent for large-scale data processing:

Let's begin by installing the ClickHouse Connect library for Python:

bash
pip install clickhouse-connect

Now we'll import the library and create a client connection:

python
import clickhouse_connect
client = clickhouse_connect.get_client(host='localhost')

Here's how you can merge your files using a single UNION ALL query:

python
query = f"""
CREATE TABLE merged_file AS
  SELECT * FROM file('path/to/file1.json', json)
  UNION ALL
  SELECT * FROM file('path/to/file2.json', json)
"""
client.command(query)

Then export your merged data to a file:

python
export_query = f"""
SELECT * FROM merged_file 
INTO OUTFILE 'path/to/merged_file.json'
FORMAT json
"""
client.command(export_query)

Need to merge more than two files? Just add more UNION ALL statements like this:

python
query = f"""
CREATE TABLE merged_file AS
  SELECT * FROM file('path/to/file1.json', json)
  UNION ALL
  SELECT * FROM file('path/to/file2.json', json)
  UNION ALL
  SELECT * FROM file('path/to/file3.json', json)
"""
client.command(query)

Want to skip the intermediate table? You can merge directly to a file in one step:

python
direct_query = f"""
SELECT * FROM file('path/to/file1.json', json)
UNION ALL
SELECT * FROM file('path/to/file2.json', json)
INTO OUTFILE 'path/to/merged_file.json'
FORMAT json
"""
client.command(direct_query)

ClickHouse really shines when you're working with massive datasets - it's a powerful columnar database that processes large volumes of data lightning fast, making it perfect for merging even the largest files.