[Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

Paul Moore p.f.moore at gmail.com
Mon Mar 27 11:41:34 EDT 2017


On 27 March 2017 at 15:48, Eric V. Smith <eric at trueblade.com> wrote:
> On 3/27/17 10:40 AM, Ram Rachum wrote:
>>
>> Another idea: Maybe make json.load and json.dump support Path objects?
>
>
> json.dump requires open file objects, not strings or Paths representing
> filenames.
>
> But does this not already do what you want:
>
> Path('foo.json').write_text(json.dumps(obj))
> ?

Indeed. There have now been a few posts quoting ways of reading and
writing JSON, all of which are pretty short (if that matters). Do we
*really* need another way?

Paul


More information about the Python-ideas mailing list