materialsvirtuallab/monty

[Bug]: `Path` objects cause issues with JSON serialization

Andrew-S-Rosen opened this issue · 0 comments

Email (Optional)

No response

Version

2024.2.6

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

It would be nice to natively support the pathlib.Path object seeing as it is a first-party import in Python.

Code snippet

from monty.serialization import dumpfn, loadfn
from pathlib import Path

d = {"directory": Path.cwd()}
dumpfn(d, "test.json")

Log output

TypeError: Object of type WindowsPath is not JSON serializable

(or similar if not on Linux)



### Code of Conduct

- [X] I agree to follow this project's Code of Conduct