+-- | Helper function that returns Null or first element of the list.
+jsonHead :: (J.JSON b) => [a] -> (a -> b) -> J.JSValue
+jsonHead [] _ = J.JSNull
+jsonHead (x:_) f = J.showJSON $ f x
+
+-- | Helper for extracting Maybe values from a possibly empty list.
+getMaybeJsonHead :: (J.JSON b) => [a] -> (a -> Maybe b) -> J.JSValue
+getMaybeJsonHead [] _ = J.JSNull
+getMaybeJsonHead (x:_) f = maybe J.JSNull J.showJSON (f x)
+