@@ -54,10 +54,12 @@ import Control.Monad.IO.Class (MonadIO, liftIO)
5454import Control.Monad (liftM)
5555import qualified Data.Vector as V
5656import Data.Text (Text, pack)
57+import Data.Text.Read (signed, decimal, double)
5758import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
5859import Data.Text.Encoding.Error (lenientDecode)
5960import qualified Data.HashMap.Strict as M
6061import Data.Typeable
62+import Data.Attoparsec.Number
6163
6264encode :: ToJSON a => a -> ByteString
6365encode obj = unsafePerformIO $
@@ -150,14 +152,23 @@ parseScalar v a = do
150152 case a of
151153 Nothing -> return res
152154 Just an -> do
153− lift $ modify (Map.insert an $ String res)
155+ lift $ modify (Map.insert an $ textToValue res)
154156 return res
155157
158+textToValue :: Text -> Value -- FIXME check for quoting style?
159+textToValue "true" = Bool True
160+textToValue "false" = Bool False
161+textToValue "null" = Null
162+textToValue t
163+ | Right (x, "") <- signed decimal t = Number $ I x
164+ | Right (x, "") <- double t = Number $ D x
165+ | otherwise = String t
166+
156167parseO :: C.Sink Event Parse Value
157168parseO = do
158169 me <- CL.head
159170 case me of
160− Just (EventScalar v _t _s a) -> fmap String $ parseScalar v a
171+ Just (EventScalar v _t _s a) -> fmap textToValue $ parseScalar v a
161172 Just (EventSequenceStart a) -> parseS a id
162173 Just (EventMappingStart a) -> parseM a M.empty
163174 Just (EventAlias an) -> do