You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何手动编辑100MB级大型JSON文件?(Windows环境)

Hey, let's tackle this problem step by step—since you're on Windows, dealing with a 100MB JSON file, and can't use online tools or basic editors that crash, here are some practical solutions tailored to your needs:

1. Ditch Jupyter: Use a Plain Python Script (Fast & Flexible)

The "IOPub data rate exceeded" error is specific to Jupyter's output limits, so switching to a standard .py script eliminates that issue entirely. Best of all, you can process the file line by line (no loading the entire 100MB into memory) and control exactly how many objects you inspect/modify at first.

Here's a ready-to-use script that lets you check the first N objects, add properties, and save changes safely to a new file:

import json

def process_large_json(input_path, output_path, num_objects_to_check=100):
    with open(input_path, 'r', encoding='utf-8') as f_in, open(output_path, 'w', encoding='utf-8') as f_out:
        # Handle the opening bracket of the JSON array
        first_line = f_in.readline()
        f_out.write(first_line)
        
        count = 0
        for line in f_in:
            line = line.strip()
            if not line:
                continue
            # Stop when we hit the closing bracket of the array
            if line == ']':
                f_out.write('\n]')
                break
            
            # Parse a single JSON object (strip trailing commas first)
            obj = json.loads(line.rstrip(','))
            
            # Print the first N objects for inspection
            if count < num_objects_to_check:
                print(f"=== Object {count+1} ===")
                print(json.dumps(obj, indent=2, ensure_ascii=False))
                # Example: Add a new property manually for these objects
                # obj['reviewed'] = True
            
            # Add conditional logic here to modify specific objects
            # e.g., if obj.get('status') == 'pending':
            #     obj['priority'] = 'high'
            
            # Write the object back to the output file
            if count > 0:
                f_out.write(',\n')
            f_out.write(json.dumps(obj, ensure_ascii=False))
            count += 1
            
        print(f"✅ Processed {count} total objects. Modified file saved to {output_path}")

# Run the function (adjust paths and object count as needed)
process_large_json('your_large_file.json', 'modified_file.json', num_objects_to_check=100)

Why this works:

  • Memory-friendly: Only loads one object at a time, so no crashes from oversized memory usage.
  • Controllable scope: Start with 100 objects, then increase num_objects_to_check as you get comfortable.
  • Safe: Writes to a new file, so your original data stays untouched.
2. Use a Local JSON Editor Built for Large Files

If you prefer a graphical interface over coding, these Windows tools can handle 100MB JSON files without breaking a sweat:

  • VS Code + Plugins: VS Code has better large-file support than Notepad++/Sublime out of the box. Install the JSON Crack plugin to visualize the JSON structure (great for quickly scanning objects) or Large File Support to optimize performance. You can directly edit properties, search for specific objects, and save changes locally.
  • jq (Command-Line Tool): A lightweight, powerful tool for manipulating JSON. Install it via Chocolatey (choco install jq) or download the binary directly. For example:
    • View the first 100 objects: jq '.[0:100]' your_large_file.json
    • Add a new property to objects matching a condition: jq 'map(if .id < 100 then . + {reviewed: true} else . end)' your_large_file.json > modified.json
  • Notepad++ (Tweaked): If you want to stick with it, go to Settings > Preferences > Editing and uncheck "Enable file status detection". You can also install the BigFiles plugin to improve large-file handling.
3. Build a Custom TKinter App (For Full Control)

If you want a tailored graphical interface to manually inspect and modify objects, TKinter is perfect—it's built into Python, so no extra installs needed. Here's a basic framework that lets you load objects, view details, add properties, and save changes:

import tkinter as tk
from tkinter import ttk, messagebox
import json

class JSONEditor:
    def __init__(self, root):
        self.root = root
        self.root.title("Large JSON Editor")
        self.input_file = "your_large_file.json"
        self.output_file = "modified_file.json"
        self.objects = []
        self.selected_obj = None

        # UI Layout
        main_frame = ttk.Frame(root, padding=10)
        main_frame.grid(row=0, column=0, sticky="nsew")

        # Load Button
        ttk.Button(main_frame, text="Load First 100 Objects", command=self.load_objects).grid(row=0, column=0, pady=5)

        # Object List
        self.obj_list = tk.Listbox(main_frame, width=40, height=20)
        self.obj_list.grid(row=1, column=0, padx=5, pady=5)
        self.obj_list.bind('<<ListboxSelect>>', self.show_details)

        # Details Text Box
        self.details = tk.Text(main_frame, width=70, height=20)
        self.details.grid(row=1, column=1, padx=5, pady=5)

        # Add Property Section
        ttk.Label(main_frame, text="Property Key:").grid(row=2, column=0, sticky="w")
        self.key_entry = ttk.Entry(main_frame, width=20)
        self.key_entry.grid(row=2, column=1, sticky="w")

        ttk.Label(main_frame, text="Property Value:").grid(row=3, column=0, sticky="w")
        self.value_entry = ttk.Entry(main_frame, width=20)
        self.value_entry.grid(row=3, column=1, sticky="w")

        ttk.Button(main_frame, text="Add Property", command=self.add_property).grid(row=4, column=0, columnspan=2, pady=5)
        ttk.Button(main_frame, text="Save Changes", command=self.save_changes).grid(row=5, column=0, columnspan=2, pady=5)

    def load_objects(self):
        self.objects.clear()
        self.obj_list.delete(0, tk.END)
        with open(self.input_file, 'r', encoding='utf-8') as f:
            f.readline()  # Skip opening bracket
            count = 0
            for line in f:
                if count >= 100:
                    break
                line = line.strip()
                if not line or line == ']':
                    continue
                obj = json.loads(line.rstrip(','))
                self.objects.append(obj)
                self.obj_list.insert(tk.END, f"Object {count+1}: {obj.get('id', 'No ID')}")
                count += 1
        messagebox.showinfo("Success", f"Loaded {count} objects!")

    def show_details(self, event):
        selected_idx = self.obj_list.curselection()
        if not selected_idx:
            return
        idx = selected_idx[0]
        self.selected_obj = self.objects[idx]
        self.details.delete(1.0, tk.END)
        self.details.insert(1.0, json.dumps(self.selected_obj, indent=2, ensure_ascii=False))

    def add_property(self):
        if not self.selected_obj:
            messagebox.showwarning("Warning", "Select an object first!")
            return
        key = self.key_entry.get().strip()
        value = self.value_entry.get().strip()
        if not key:
            messagebox.showwarning("Warning", "Property key can't be empty!")
            return
        # Try to parse value to correct type (optional)
        try:
            value = json.loads(value)
        except:
            pass
        self.selected_obj[key] = value
        self.details.delete(1.0, tk.END)
        self.details.insert(1.0, json.dumps(self.selected_obj, indent=2, ensure_ascii=False))
        messagebox.showinfo("Success", "Property added!")

    def save_changes(self):
        with open(self.input_file, 'r', encoding='utf-8') as f_in, open(self.output_file, 'w', encoding='utf-8') as f_out:
            f_out.write(f_in.readline())  # Write opening bracket
            for i, obj in enumerate(self.objects):
                if i > 0:
                    f_out.write(',\n')
                f_out.write(json.dumps(obj, ensure_ascii=False))
            # Copy remaining objects from original file
            for line in f_in:
                line = line.strip()
                if line == ']':
                    f_out.write(',\n]')
                    break
                f_out.write(f',\n{line}'.rstrip(','))
        messagebox.showinfo("Success", f"Changes saved to {self.output_file}")

if __name__ == "__main__":
    root = tk.Tk()
    app = JSONEditor(root)
    root.mainloop()

Why this works:

  • Visual & intuitive: No coding required after setup—just click to load, select objects, and add properties.
  • Secure: 100% local, no data leaves your machine.
  • Customizable: Tweak the UI or add features like search/filter as needed.

内容的提问来源于stack exchange,提问作者Eric Hansen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:35:05