In order for an instance to be canonical (i.e. not an orphan), it needs to be defined in the same module as either the type constructor (Data.Tree
) or the class declaration (Data.Aeson.Types
). So the only way to define a non-orphan instance would be to fork aeson
(since aeson
depends on containers).
I'd recommend filing a ticket with aeson
, or possibly a pull request, to get it added upstream. Until then, if you don't plan to distribute the code, defining an orphan instance shouldn't cause much trouble. If you're working on code you want to publish, the safest solution is to create a newtype wrapper around Tree
, then make a FromJSON
instance for the newtype.