Add ToJSONKey instance for OsPath? Recommended workaround?
- Dominant language
- Haskell
- Stars
- 74
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I have a naive question (my Haskell is rusty, so bear with me). I have a strict Data.Map.Map type like `Map OsPath MyType`. (The `MyType` is just a record I have in my program and not material to this discussion.) Anyway, I want to write this map as a JSON value to disk, like `foo.json`. However I get an error from Data.Aeson about how there is no `ToJSONKey` instance for the `OsPath` type.
I have two questions:
1. Would it make sense for this library to add a `ToJSONKey` instance for `OsPath`? IIUC this library saves the raw bytes into OsPath (not caring about encoding), while still taking care to note path separators. So theoretically it appears to me that we could print out these raw bytes (and path separators) as some sort of compound JSON value. It definitely won't be as pretty as writing a basic `String` (e.g. `FilePath`) value, but at least it's something...?
2. Assuming the above is a bad idea, what is the recommended workaround? In particular my application reads files from disk, and I am basically saving the path from which the file was read as an `OsPath` (and parsing the contents as a `MyType`). I just want to use OsPath everywhere because I really enjoy the fact that the type system makes it clear how it's not just a `String` equivalent (which I've always disliked about `FilePath`). Any specific guidance here would be appreciated.
Thanks!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the reported Data.Map.Map OsPath MyType failure and the missing Data.Aeson ToJSONKey instance. Determine whether OsPath can have a suitable JSON-key representation or whether the project should recommend another approach; done means a maintainer-approved decision with corresponding implementation or explicit guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100