summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-07-26 19:15:34 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-07-26 19:15:34 -0400
commitbcc5ee4f322a139ee7cef2bae1fc9bea9f5398ca (patch)
treed4bfd67f6efcb0000c8749aaa6cdae964b333edc /Utility
parente0b3fc906467ded314c75417d5b11b4b04375d1a (diff)
Removed dependency on json library; all JSON is now handled by aeson.
I've eyeballed all --json commands, and the only difference should be that some fields are re-ordered.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/JSONStream.hs35
1 files changed, 17 insertions, 18 deletions
diff --git a/Utility/JSONStream.hs b/Utility/JSONStream.hs
index efee1dec6..af321b2f9 100644
--- a/Utility/JSONStream.hs
+++ b/Utility/JSONStream.hs
@@ -14,31 +14,30 @@ module Utility.JSONStream (
end
) where
-import qualified Text.JSON as JSON
-import qualified Data.Aeson as Aeson
+import Data.Aeson
+import qualified Data.Text as T
import qualified Data.ByteString.Lazy.UTF8 as B
-{- Only JSON objects can be used as chunks in the stream, not
- - other values.
- -
- - Both Aeson and Text.Json objects are supported. -}
-data JSONChunk a where
- JSONObject :: JSON.JSON a => [(String, a)] -> JSONChunk [(String, a)]
- AesonObject :: Aeson.Object -> JSONChunk Aeson.Object
-
-encodeJSONChunk :: JSONChunk a -> String
-encodeJSONChunk (JSONObject l) = JSON.encodeStrict $ JSON.toJSObject l
-encodeJSONChunk (AesonObject o) = B.toString (Aeson.encode o)
-
-{- Text.JSON and Aeson do not support building up a larger JSON document
- - piece by piece as a stream. To support streaming, a hack. The final "}"
- - is left off the object, allowing it to be added to later. -}
+data JSONChunk v where
+ JSONChunk :: ToJSON v => [(String, v)] -> JSONChunk [(String, v)]
+ AesonObject :: Object -> JSONChunk Object
+
+encodeJSONChunk :: JSONChunk v -> B.ByteString
+encodeJSONChunk (JSONChunk l) = encode $ object $ map mkPair l
+ where
+ mkPair (s, v) = (T.pack s, toJSON v)
+encodeJSONChunk (AesonObject o) = encode o
+
+{- Aeson does not support building up a larger JSON object piece by piece
+ - with streaming output. To support streaming, a hack:
+ - The final "}" is left off the JSON, allowing more chunks to be added
+ - to later. -}
start :: JSONChunk a -> String
start a
| last s == endchar = init s
| otherwise = bad s
where
- s = encodeJSONChunk a
+ s = B.toString $ encodeJSONChunk a
add :: JSONChunk a -> String
add a