Skip to content

json.tool error I/O operation on close file with --json-lines #138960

Closed as duplicate

Description

@mpkocher

Bug report

Bug description:

When using python -m json.tool --json-lines example.jline, the file handle is closed before the generator is consumed.

>> python --version
Python 3.13.2
>> cat example.jline                             
{"name": "Gilbert", "session": "2013", "score": 24, "completed": true}
{"name": "Alexa", "session": "2013", "score": 29, "completed": true}
{"name": "May", "session": "2012B", "score": 14, "completed": false}
{"name": "Deloise", "session": "2012A", "score": 19, "completed": true} 
>> python -m json.tool --json-lines example.jline
I/O operation on closed file.
>> echo $?

Requirements:

  • The --json-lines option with an explicit file should not raise an I/O error.
  • Add a test for the explicit case for --json-lines flag and a positional argument to json.tool.

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Sep 16, 2025
  2. hugovk commented on Sep 16, 2025

    @hugovk
    Member

    Thanks for the report, this is a duplicate of #132631.

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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions