GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JSON CLI: I/O operation on closed file" when parsing JSON Lines file · Issue #132631 · python/cpython

JSON CLI: I/O operation on closed file" when parsing JSON Lines file #132631

New issue
Copy link
New issue
Copy link
Closed
Closed
JSON CLI: I/O operation on closed file" when parsing JSON Lines file#132631
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@hugovk
hugovk
opened on Apr 17, 2025
Issue body actions

Bug report

Bug description:

With any JSON Lines file, such as:

❯ cat input.jsonl
{"ingredients":["frog", "water", "chocolate", "glucose"]}
{"ingredients":["chocolate","steel bolts"]}

This works on Python 3.12:

❯ python3.12 --version
Python 3.12.10

❯ python3.12 -m json.tool --json-lines input.jsonl
{
    "ingredients": [
        "frog",
        "water",
        "chocolate",
        "glucose"
    ]
}
{
    "ingredients": [
        "chocolate",
        "steel bolts"
    ]
}

But not 3.13 or higher:

❯ python3.13 --version
Python 3.13.3

❯ python3.13 -m json.tool --json-lines input.jsonl
I/O operation on closed file.

❯ python3.14 --version
Python 3.14.0a7

❯ python3.14 -m json.tool --json-lines input.jsonl
I/O operation on closed file.

❯ ./python.exe --version --version
Python 3.14.0a7+ (heads/main:e42bda94411, Apr 17 2025, 14:59:38) [Clang 16.0.0 (clang-1600.0.26.6)]

❯ ./python.exe Lib/test/test_json/test_tool.py -h

❯ ./python.exe -m json.tool --json-lines input.jsonl
I/O operation on closed file.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

macOS, Linux

Linked PRs

  • gh-132631: Fix "I/O operation on closed file" when parsing JSON Lines file #132632
  • gh-132631: Fix json.tool when using --json-lines and a file as input #138961
  • [3.14] gh-132631: Fix "I/O operation on closed file" when parsing JSON Lines file (GH-132632) #148921
  • [3.13] gh-132631: Fix "I/O operation on closed file" when parsing JSON Lines file (GH-132632) #148922

Activity

  1. hugovk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    on Apr 17, 2025
  2. hugovk
    marked json.tool error I/O operation on close file with --json-lines #138960 as a duplicate of this issue on Sep 16, 2025
  3. nineteendo commented on Sep 16, 2025

    @nineteendo
    nineteendo
    on Sep 16, 2025 · Hidden as resolved
    show commentMore actions
  4. hugovk
    added this to JSON issueson Sep 16, 2025
  5. mpkocher commented on Sep 16, 2025

    @mpkocher
    mpkocher
    on Sep 16, 2025
    Contributor
    More actions

    There's also an issue with the "in place" functionality. This is captured in a unit test, but there's no mention of this requirement or functionality in the code.

    In place can overwrite the current file, but requires special attention.

    python -m json.tool example.json example.json

    For the in place functionality, it should probably write to a tmp file, then atomically overwrite the original file and delete the tmp file.

    The use case of in place and --json-lines is a bit odd (needs --no-indent), but it still should mechanically work and not error out.

    >> cat a.jline                                                
    {"alpha": 123,                     "beta": 122345}
    {"alpha": 124,       "beta": 456}

    From a file, using --no-indent can cleanup a file.

    >> python  -m json.tool --no-indent --json-lines a.jline 
    {"alpha": 123, "beta": 122345}
    {"alpha": 124, "beta": 456}

    In place will break and overwrite the original file and leave an empty file, effectively deleting(!) the original file.

    >> cat a.jline       
    {"alpha": 123,                     "beta": 122345}
    {"alpha": 124,       "beta": 456}
    >> python -m json.tool --json-lines --no-indent a.jline a.jline
    I/O operation on closed file.
    >> cat a.jline 
    >>
  6. hugovk
    added 3 commits that reference this issue on Apr 23, 2026

    gh-132631: Fix "I/O operation on closed file" when parsing JSON Lines…

    42d645a

    [3.14] gh-132631: Fix "I/O operation on closed file" when parsing JSO…

    31ba91a

    [3.13] gh-132631: Fix "I/O operation on closed file" when parsing JSO…

    e4ae72a
  7. hugovk
    closed this as completedon Apr 23, 2026
  8. github-project-automation
    moved this to Done in JSON issueson Apr 23, 2026
  9. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-132631: Fix "I/O operation on closed file" when parsing JSON…

    a17f00e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • JSON issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.