Skip to content

Add ToJSONKey instance for OsPath? Recommended workaround? #256

@listx

Description

@listx

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions