Skip to content

Commit 1181490

Browse files
committed
Prepare for 0.1.1.0 release
1 parent ee52202 commit 1181490

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
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.

json-syntax.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 2.2
22
name: 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
55
description:
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

src/Json/Query.hs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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"

0 commit comments

Comments
 (0)