Here is a Python solution to your problem.

Don't forget to change the in_file_path to the location of your big JSON file.

import json

in_file_path='path/to/file.json' # Change me!

with open(in_file_path,'r') as in_json_file:

    # Read the file and convert it to a dictionary
    json_obj_list = json.load(in_json_file)

    for json_obj in json_obj_list:
        filename=json_obj['_id']+'.json'

        with open(filename, 'w') as out_json_file:
            # Save each obj to their respective filepath
            # with pretty formatting thanks to `indent=4`
            json.dump(json_obj, out_json_file, indent=4)

Side Note: I ran this in Python3, it should work in Python2 as well

Answer from Stefan Collier on Stack Overflow
Top answer
1 of 3
5

Here is a Python solution to your problem.

Don't forget to change the in_file_path to the location of your big JSON file.

import json

in_file_path='path/to/file.json' # Change me!

with open(in_file_path,'r') as in_json_file:

    # Read the file and convert it to a dictionary
    json_obj_list = json.load(in_json_file)

    for json_obj in json_obj_list:
        filename=json_obj['_id']+'.json'

        with open(filename, 'w') as out_json_file:
            # Save each obj to their respective filepath
            # with pretty formatting thanks to `indent=4`
            json.dump(json_obj, out_json_file, indent=4)

Side Note: I ran this in Python3, it should work in Python2 as well

2 of 3
1

I ran into this problem today as well, and did some research. Just want to share the resulting Python snippet that lets you also customise the length of split files (thanks to this slicing method).

import os
import json
from itertools import islice

def split_json(
    data_path,
    file_name,
    size_split=1000,
):
    """Split a big JSON file into chunks.
    data_path : str, "data_folder"
    file_name : str, "data_file" (exclude ".json")
    """
    with open(os.path.join(data_path, file_name + ".json"), "r") as f:
        whole_file = json.load(f)

    split = len(whole_file) # size_split

    for i in range(split + 1):
        with open(os.path.join(data_path, file_name + "_"+ str(split+1) + "_" + str(i+1) + ".json"), 'w') as f:
            json.dump(dict(islice(whole_file.items(), i*size_split, (i+1)*size_split)), f)
    return

Update: Then, when you need to combine them together again, use the following code:

json_all = dict()
split = 4         # this is the 1-based actual number of splits

for i in range(1, split+1):
    with open(os.path.join("data_folder", "data_file_" + str(split) + "_" + str(i) + ".json"), 'r') as f:
        json_i = json.load(f)
        json_all.update(json_i)
🌐
GitHub
github.com › jhsu98 › json-splitter
GitHub - jhsu98/json-splitter · GitHub
Navigate to the directory where the script exists and begin by typing python3 json-splitter.py · Enter the name of the JSON file (include the extension) when prompted, then enter the maximum number of MB for each file.
Starred by 54 users
Forked by 20 users
Languages   Python
Discussions

python - Split a large json file into multiple smaller files - Stack Overflow
I have a large JSON file, about 5 million records and a file size of about 32GB, that I need to get loaded into our Snowflake Data Warehouse. I need to get this file broken up into chunks of about ... More on stackoverflow.com
🌐 stackoverflow.com
Split 150GB json file with Python?
I have questions... What do you want to achieve by "viewing" a 1GB part of a JSON file? what's the end-goal? How did you end up with 150GB file to begin with? Technically it's possible to split a file using python, the question remains what exactly do you hope to understand from these "splits"... More on reddit.com
🌐 r/learnpython
52
48
March 3, 2024
Split one json file into multiple files of same size
with open ('some.json') as json_file: json_data = json_file.read() for i, char in enumerate(json_data): with open(str(i), 'w') as out_file: out_file.write(char) Seriously though, what are you trying to solve? ZIP can generate similar-sized archives, or you can use the split utility. More on reddit.com
🌐 r/learnpython
6
2
December 25, 2019
How to split data from a json file into two json files with Python - Stack Overflow
I have a json file with two sets of data and I'd like to split this one json file into two separate json file so that each file has one set of data. For example, the existing json file looks like t... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
jhsu98.medium.com › how-to-build-a-command-line-json-splitter-72061b0f20a6
How to Build a Command Line JSON Splitter | by Jonathan Hsu | Medium
March 10, 2019 - The project is available at ... installed Python 3.x and know that to run the script you’ll want to type python3 json-splitter.py...
🌐
Reddit
reddit.com › r/learnpython › split 150gb json file with python?
r/learnpython on Reddit: Split 150GB json file with Python?
March 3, 2024 -

I haven't had much to do with json files so far, but now I need them for datahoarding. Now I have a 150GB json file here and can't open it because there's not enough free HDD & RAM on my laptop and computers.

So I have to split the file into several pieces (prefer 1 GB files) and open and view them one after the other. How can I do this on Windows?

Google spits out ancient results (and mostly for Linux) which, as usual, have contradictory information.

Maybe it is possible with a Python script. I don't care if the last and first line of the new file look slightly different than in the original json file

🌐
Plain English
plainenglish.io › blog › split-big-json-file-into-small-splits
Split a Big JSON File into Smaller Files using Python
So, I created a simple JSON CSV converter that you can use to convert all the JSON files into one code without converting them one by one. This is the JSON CSV converter code. You need to provide the number of splits according to your requirement. In my work, I split the big JSON file into 8 splits.
🌐
Python Forum
python-forum.io › thread-37678.html
Python Split json into separate json based on node value
Using python I want to split a json file into multiple files based on the 'transactionTypeName' within the transacations.details. In each file I want the rest of the details as well starting from careperson to username. Below is the json file. Had to...
Find elsewhere
Top answer
1 of 2
1

You can try:

import json

dct = {
    "client_id": {"0": "abc123", "1": "def456"},
    "client_name": {"0": "companyA", "1": "companyB"},
    "revenue": {"0": "54,786", "1": "62,754"},
    "rate": {"0": "4", "1": "5"},
}

tmp = {}
for k, v in dct.items():
    for kk, vv in v.items():
        tmp.setdefault(kk, {}).update({k: vv})

for i, v in enumerate(tmp.values(), 1):
    with open(f"File{i}.json", "w") as f_out:
        json.dump(v, f_out, indent=4)

This creates two files File1.json, File2.json:

{
    "client_id": "abc123",
    "client_name": "companyA",
    "revenue": "54,786",
    "rate": "4"
}

and

{
    "client_id": "abc123",
    "client_name": "companyA",
    "revenue": "54,786",
    "rate": "4"
}

EDIT: To create output dictionary:

dct = {
    "client_id": {"0": "abc123", "1": "def456"},
    "client_name": {"0": "companyA", "1": "companyB"},
    "revenue": {"0": "54,786", "1": "62,754"},
    "rate": {"0": "4", "1": "5"},
}

tmp = {}
for k, v in dct.items():
    for kk, vv in v.items():
        tmp.setdefault(kk, {}).update({k: vv})

out = {}
for i, v in enumerate(tmp.values(), 1):
    out[f"File{i}"] = v

print(out)

Prints:

{
    "File1": {
        "client_id": "abc123",
        "client_name": "companyA",
        "revenue": "54,786",
        "rate": "4",
    },
    "File2": {
        "client_id": "def456",
        "client_name": "companyB",
        "revenue": "62,754",
        "rate": "5",
    },
}
2 of 2
0

You can use the json package to read your json file and process it in a for loop

import json

with open('json_data.json') as json_file:
    data = json.load(json_file)

# Contains the "0", "1", ...
list_of_new_dicts = data["client_id"].keys()
new_data = {}

for key, dico in data.items():
    for num, value in dico.items():
        new_data[num][key] = value

Your new data dictionnary should look like the following:

{
  "0":{
    "client_id" : "abc123",
    "client_name": "companyA",
    "revenue": "54,786", 
    "rate" : "4"
  },
  "1":{ 
    "client_id" :  "def456",
    "client_name": "companyB",
    "revenue":  "62,754",
    "rate" :  "5"
  }
}

Then to save the file you can do something like:

with open('json_data_0.json', 'w') as outfile:
    json.dump(new_data["0"], outfile)
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › How-to-split-large-json-file-into-multiple-json-files-in › m-p › 364136
Solved: How to split large json file into multiple json fi... - Cloudera Community - 364136
March 2, 2023 - That example generates a file with 102 records and on SlitRecord we use a JsontTreeReader that will split by 3 records and writes the flowfiles out, In this case per 3 per flowFile generating 34 FlowFiles. ... In your case and based on your screenshot I would change split count to be 1500000 ( or another number based on your needs ) ... Try to look into QueryRecord or PartitionRecord Processors.
🌐
GitHub
gist.github.com › 97-109-107 › bf9211c4a160deb4ee15
A tiny python thing to split big json files into smaller junks. · GitHub
November 21, 2014 - A tiny python thing to split big json files into smaller junks. - json-split.py
🌐
Merge-json-files
merge-json-files.com › blog › how-to-split-json-files
How to Split JSON File into Multiple Files: Step-by-Step Guide | Merge JSON Files
April 3, 2025 - Learn how to split large JSON files into smaller parts using Python, jq command-line, and online tools. A complete guide for developers handling big JSON datasets and nested structures.
🌐
Merge-json-files
merge-json-files.com › json-file-splitter
Split JSON Files Instantly | Free Online JSON Splitter Tool
Use our online tool to split large JSON files into parts easily. Free, safe, and fast — no login or install needed.
🌐
PyPI
pypi.org › project › json-file-split
json-file-split
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
GitHub
gist.github.com › stp-ip › 5759205
Python script to split starred.json into smaller junks to make them usable for alternatives. Sometimes trying to import starred.json files with more than 50mb or even less fail. -> split it and it should work. · GitHub
June 1, 2016 - Python script to split starred.json into smaller junks to make them usable for alternatives. Sometimes trying to import starred.json files with more than 50mb or even less fail. -> split it and it should work. - split_starred_json.py
🌐
Stack Overflow
stackoverflow.com › questions › 72913506 › python-split-json-into-separate-json-based-on-node-value
Python Split json into separate json based on node value - Stack Overflow
Then loop over until all transactions have been split. This could be simplified by copying the JSON read from the file to a temporary object. In Python 3, it would look like this (Added comments to explain each step): import json # Load JSON data from a file into object fileRead = open('test.json', 'r') jsonContent = json.load(fileRead) fileRead.close() # Loop through each transaction read from the file (3 in the example) for transaction in jsonContent['transactions']: jsonFileContent = {} # Loop through each json key value pair read from the object.