From f43dc62d127bf87815a480f062b98c9c6dfb0bac Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 10 Sep 2017 22:31:57 -0400 Subject: [PATCH] Define a JSONFields bridge for ToJSON instances. --- src/Data/JSON/Fields.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Data/JSON/Fields.hs b/src/Data/JSON/Fields.hs index ad56a8aab..07b5bfde9 100644 --- a/src/Data/JSON/Fields.hs +++ b/src/Data/JSON/Fields.hs @@ -28,3 +28,10 @@ instance (Apply1 Foldable fs) => ToJSONFields1 (Union fs) where instance (ToJSON a, ToJSON b) => ToJSONFields (a, b) where toJSONFields (a, b) = [ "before" .= a, "after" .= b ] + + +newtype JSONFields a = JSONFields { unJSONFields :: a } + +instance (ToJSONFields a) => ToJSON (JSONFields a) where + toJSON = object . toJSONFields . unJSONFields + toEncoding = pairs . mconcat . toJSONFields . unJSONFields