data Counter = Counter Int deriving Show
We derive instances of ‘ToJson’ and ‘FromJson’ for this type using the following template Haskell code:
$(derive[''Counter])
Now, if we don't define custom ‘ToJson’ or ‘FromJson’ instances, the default behavior is this:
toJsonString (Counter 7)
--> "7"
fromJsonString (undefined :: Counter) "7"
--> Counter 7
This is a big improvement over the default behavior in older versions, which would have converted (Counter 7) to a single-element JSON array.