File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Revision history for json-syntax
22
3+ ## 0.1.1.0 -- 2020-05-01
4+
5+ * Add ` encode ` .
6+
37## 0.1.0.0 -- 2020-01-20
48
59* Initial release.
Original file line number Diff line number Diff line change 11cabal-version : 2.2
22name : json-syntax
3- version : 0.1.0 .0
4- synopsis : High-performance JSON parser
3+ version : 0.1.1 .0
4+ synopsis : High-performance JSON parser and encoder
55description :
66 This library parses JSON into a @Value@ type that is consistent with the
77 ABNF described in [RFC 7159](https://tools.ietf.org/html/rfc7159). The
@@ -36,7 +36,7 @@ library
3636 , bytesmith >= 0.3.2 && < 0.4
3737 , bytestring >= 0.10.8 && < 0.11
3838 , primitive >= 0.7 && < 0.8
39- , scientific-notation >= 0.1.1 && < 0.2
39+ , scientific-notation >= 0.1.2 && < 0.2
4040 , text-short >= 0.1.3 && < 0.2
4141 hs-source-dirs : src
4242 default-language : Haskell2010
Original file line number Diff line number Diff line change 1+ module Json.Query
2+ ( Path (.. )
3+ , query
4+ ) where
5+
6+ -- Revisit this later.
7+ -- Do not release this library with this module still here.
8+
9+ data Path
10+ = Key {- # UNPACK #-} !ShortText ! Path
11+ -- ^ JSON path element of a key into an object, \"object.key\".
12+ | Index {- # UNPACK #-} !Int ! Path
13+ -- ^ JSON path element of an index into an array, \"array[index]\".
14+ | Nil
15+
16+ query :: Path -> Value -> Maybe Value
17+ query = go where
18+ go Nil v = Just v
19+ go (Key k p) (Object mbrs) = foldr
20+ (\ (Member key val) other -> if key == k
21+ then Just val
22+ else other
23+ ) Nothing mbrs >>= go p
24+ go (Index i p) (Array vs) = Chunks. index vs i >>= go p
25+ go _ _ = Nothing
26+
27+ -- Example Use:
28+ -- data Foo = Foo String String String
29+ -- object :: Parser Value (Chunks _)
30+ -- myParser :: Parser Value Foo
31+ -- myParser =
32+ -- object
33+ -- >->
34+ -- Foo
35+ -- <$> path "foo"
36+ -- <*> (path "bar" >-> object >-> path "baz")
37+ -- <*> path "gaz"
You can’t perform that action at this time.
0 commit comments