Skip to content

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

@mpkocher

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions