JSON-Combinator-Examples (empty) → 0.0.1
raw patch · 4 files changed
+96/−0 lines, 4 filesdep +JSON-Combinatordep +JSONbdep +basesetup-changed
Dependencies added: JSON-Combinator, JSONb, base, bytestring, json
Files
- JSON-Combinator-Examples.cabal +30/−0
- LICENSE +27/−0
- Setup.hs +3/−0
- Text/JSON/Combinator/Examples.hs +36/−0
+ JSON-Combinator-Examples.cabal view
@@ -0,0 +1,30 @@+Name: JSON-Combinator-Examples+Version: 0.0.1+License: BSD3+License-File: LICENSE+Author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>+Maintainer: Tony Morris+Synopsis: Example uses of the JSON-Combinator library.+Category: Combinators+Description:+ Example uses of the JSON-Combinator library.+ .+ /The example JSON files use a specific JSON format because of a bug in json (Text.JSON)./+Cabal-version: >= 1.2+Build-Type: Simple++Flag small_base+ Description: Choose the new, split-up base package.++Library+ Build-Depends:+ base < 5 && >= 4+ , bytestring+ , JSONb+ , json+ , JSON-Combinator >= 0.1.2++ GHC-Options: -Wall++ Exposed-Modules: Text.JSON.Combinator.Examples+
+ LICENSE view
@@ -0,0 +1,27 @@+Copyright 2009 Tony Morris++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.+3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple+main = defaultMain+
+ Text/JSON/Combinator/Examples.hs view
@@ -0,0 +1,36 @@+module Text.JSON.Combinator.Examples where++import Text.JSON.Combinator+import qualified Text.JSON as J+import Text.JSONb+import Text.JSON.Parsec+import Control.Applicative+import qualified Data.ByteString as S++-- | Using both @Text.JSON@ and @Text.JSONb@,+-- then given a file name of a JSON object,+-- go through each field of that object and:+--+-- * If it is a string, reverse it+--+-- * If it is a number, add 1 to it+--+-- * If it is a boolean, invert it+--+-- then pretty-print the result of each of the parsers.+example1 ::+ FilePath -- ^ The JSON object file name+ -> IO ()+example1 p =+ do r1 <- readJSONFile p :: IO (Either String JSON)+ r2 <- readJSONFile p :: IO (Either ParseError J.JSValue)+ let f r = withObjectFields (+ withString r+ . withNumber (+1)+ . jnot+ )+ k1 = printJSON . f S.reverse <$> r1+ k2 = printJSON . f reverse <$> r2+ either print S.putStrLn k1+ either print putStrLn k2+