@@ -18,19 +18,21 @@ module Data.Aeson.Encode
1818import Blaze.ByteString.Builder
1919import Blaze.ByteString.Builder.Char.Utf8
2020import Data.Aeson.Types (ToJSON(..), Value(..))
21+import Data.Attoparsec.Number (Number(..))
2122import Data.Monoid (mappend)
2223import Numeric (showHex)
23−import qualified Data.ByteString.Char8 as B
2424import qualified Data.ByteString.Lazy.Char8 as L
2525import qualified Data.Map as M
2626import qualified Data.Text as T
2727import qualified Data.Vector as V
28+import qualified Text.Show.ByteString as S
2829
2930-- | Encode a JSON value to a 'Builder'.
3031fromValue :: Value -> Builder
3132fromValue Null = fromByteString "null"
3233fromValue (Bool b) = fromByteString $ if b then "true" else "false"
33−fromValue (Number n) = fromByteString (B.pack (show n))
34+fromValue (Number (I n)) = fromLazyByteString (S.show n)
35+fromValue (Number (D n)) = fromLazyByteString (S.show n)
3436fromValue (String s) = string s
3537fromValue (Array v)
3638 | V.null v = fromByteString "[]"
@@ -52,7 +54,7 @@ string s = fromChar '"' `mappend` quote s `mappend` fromChar '"'
5254 where
5355 quote q = case T.uncons t of
5456 Just (c,t') -> fromText h `mappend` escape c `mappend` quote t'
55− Nothing -> fromText h
57+ Nothing -> fromText h
5658 where (h,t) = T.break isEscape q
5759 isEscape c = c == '\"' || c == '\\' || c < '\x20'
5860 escape '\"' = fromByteString "\\\""