diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index a4b18f6b0..ea9b73401 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -36,8 +36,8 @@ json diff sources = toLazyByteString . fromEncoding . pairs $ newtype NumberedLine a = NumberedLine (Int, Line a) instance ToJSON a => ToJSON (NumberedLine a) where - toJSON (NumberedLine (n, a)) = object [ "number" .= n, "terms" .= unLine a ] - toEncoding (NumberedLine (n, a)) = pairs ("number" .= n <> "terms" .= unLine a) + toJSON (NumberedLine (n, a)) = object (lineFields n a) + toEncoding (NumberedLine (n, a)) = pairs $ mconcat (lineFields n a) instance ToJSON Category where toJSON (Other s) = String $ T.pack s toJSON s = String . T.pack $ show s @@ -59,6 +59,9 @@ instance ToJSON (Term leaf Info) where toJSON (info :< syntax) = object (termFields info syntax) toEncoding (info :< syntax) = pairs $ mconcat (termFields info syntax) +lineFields :: (ToJSON a, KeyValue kv) => Int -> Line a -> [kv] +lineFields n line = [ "number" .= n, "terms" .= unLine line ] + termFields :: (ToJSON recur, KeyValue kv) => Info -> Syntax leaf recur -> [kv] termFields (Info range categories) syntax = "range" .= range : "categories" .= categories : case syntax of Leaf _ -> []