@@ -72,9 +72,11 @@ module Text.Pandoc
7272 , readOPML
7373 , readHaddock
7474 , readNative
75+ , readJSON
7576 -- * Writers: converting /from/ Pandoc format
7677 , Writer (..)
7778 , writeNative
79+ , writeJSON
7880 , writeMarkdown
7981 , writePlain
8082 , writeRST
@@ -190,9 +192,8 @@ markdown o s = do
190192
191193-- | Association list of formats and readers.
192194readers :: [(String, ReaderOptions -> String -> IO Pandoc)]
193−readers = [("native" , \_ s -> return $ readNative s)
194− ,("json" , \_ s -> return $ checkJSON
195− $ decode $ UTF8.fromStringLazy s)
195+readers = [ ("native" , \_ s -> return $ readNative s)
196+ ,("json" , \o s -> return $ readJSON o s)
196197 ,("markdown" , markdown)
197198 ,("markdown_strict" , markdown)
198199 ,("markdown_phpextra" , markdown)
@@ -205,8 +206,8 @@ readers = [("native" , \_ s -> return $ readNative s)
205206 ,("textile" , \o s -> return $ readTextile o s) -- TODO : textile+lhs
206207 ,("html" , \o s -> return $ readHtml o s)
207208 ,("latex" , \o s -> return $ readLaTeX o s)
208− ,("haddock" , \o s -> return $ readHaddock o s)
209− ]
209+ ,("haddock" , \o s -> return $ readHaddock o s)
210+ ]
210211
211212data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
212213 | IOStringWriter (WriterOptions -> Pandoc -> IO String)
@@ -216,12 +217,12 @@ data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
216217writers :: [ ( String, Writer ) ]
217218writers = [
218219 ("native" , PureStringWriter writeNative)
219− ,("json" , PureStringWriter $ \_ -> UTF8.toStringLazy . encode)
220+ ,("json" , PureStringWriter writeJSON)
220221 ,("docx" , IOByteStringWriter writeDocx)
221− ,("odt" , IOByteStringWriter writeODT)
222− ,("epub" , IOByteStringWriter $ \o ->
222+ ,("odt" , IOByteStringWriter writeODT)
223+ ,("epub" , IOByteStringWriter $ \o ->
223224 writeEPUB o{ writerEpubVersion = Just EPUB2 })
224− ,("epub3" , IOByteStringWriter $ \o ->
225+ ,("epub3" , IOByteStringWriter $ \o ->
225226 writeEPUB o{ writerEpubVersion = Just EPUB3 })
226227 ,("fb2" , IOStringWriter writeFB2)
227228 ,("html" , PureStringWriter writeHtmlString)
@@ -359,3 +360,10 @@ instance (Data a) => ToJsonFilter (a -> IO [a]) where
359360checkJSON :: Maybe a -> a
360361checkJSON Nothing = error "Error parsing JSON"
361362checkJSON (Just r) = r
363+
364+readJSON :: ReaderOptions -> String -> Pandoc
365+readJSON _ = checkJSON . decode . UTF8.fromStringLazy
366+
367+writeJSON :: WriterOptions -> Pandoc -> String
368+writeJSON _ = UTF8.toStringLazy . encode
369+