Skip to content

Commit 1b8bc20

Browse files
committed
Update for json-syntax 0.3 and release
1 parent a2a7e71 commit 1b8bc20

File tree

8 files changed

+32
-24
lines changed

8 files changed

+32
-24
lines changed

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-query
22

3+
## 0.3.0.0 -- 2025-07-14
4+
5+
* Update to work with json-syntax
6+
37
## 0.2.3.1 -- 2024-01-29
48

59
* Update package metadata.

json-query.cabal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.4
22
name: json-query
3-
version: 0.2.3.1
3+
version: 0.3.0.0
44
synopsis: Kitchen sink for querying JSON
55
description:
66
The library complements json-syntax by making available several
@@ -17,7 +17,7 @@ copyright: 2020 Andrew Martin
1717
category: Data
1818
build-type: Simple
1919
extra-doc-files: CHANGELOG.md
20-
tested-with: GHC ==9.4.8 || ==9.6.3 || ==9.8.1
20+
tested-with: GHC ==9.6.3 || ==9.8.1
2121

2222
common build-settings
2323
default-language: Haskell2010
@@ -38,12 +38,13 @@ library
3838
, bytebuild >=0.3.5 && <0.4
3939
, bytestring >=0.10 && <0.12
4040
, contiguous >=0.6.4 && <0.7
41-
, json-syntax >=0.2.2 && <0.3
41+
, json-syntax >=0.3 && <0.4
4242
, primitive >=0.7 && <0.10
4343
, primitive-unlifted >=0.1.3 && <2.3
4444
, profunctors >=5.6.2 && <5.7
4545
, scientific-notation >=0.1.5 && <0.2
46-
, text-short >=0.1.3 && <0.2
46+
, text >=2.1.2
47+
, text-short >=0.1.5
4748
, transformers >=0.5.6 && <0.7
4849

4950
hs-source-dirs: src
@@ -73,7 +74,6 @@ test-suite test
7374
, tasty-hspec >=1.2.0.4
7475
, tasty-hunit >=0.10.0.2
7576
, text >=1.2
76-
, text-short
7777

7878
source-repository head
7979
type: git

src/Json/Arrow.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import Data.Number.Scientific (Scientific)
5959
import Data.Primitive (SmallArray)
6060
import Data.Primitive.Unlifted.Array (UnliftedArray)
6161
import Data.Profunctor (Profunctor (..))
62+
import Data.Text (Text)
6263
import Data.Text.Short (ShortText)
6364
import Data.Word (Word16, Word64)
6465
import Json (Member (Member), Value (Array, Number, Object, String))
@@ -94,7 +95,7 @@ array = P $ \ctx v -> case v of
9495
Array membs -> Right (ctx, Elements membs)
9596
_ -> Left (Errors.singleton (Error "expected array" ctx))
9697

97-
string :: Value ~> ShortText
98+
string :: Value ~> Text
9899
string = P $ \ctx v -> case v of
99100
String str -> Right (ctx, str)
100101
_ -> Left (Errors.singleton (Error "expected string" ctx))
@@ -106,7 +107,7 @@ string = P $ \ctx v -> case v of
106107
Failure context includes the index of non-string value if any values in
107108
the array are not strings.
108109
-}
109-
strings :: Value ~> UnliftedArray ShortText
110+
strings :: Value ~> SmallArray Text
110111
strings = P $ \ctx v -> case v of
111112
Array membs -> runST $ runExceptT $ do
112113
xs <-
@@ -137,15 +138,15 @@ null = P $ \ctx v -> case v of
137138

138139
newtype Members = Members {unMembers :: SmallArray Member}
139140

140-
member :: ShortText -> Members ~> Value
141+
member :: Text -> Members ~> Value
141142
member k = P $ \ctx xs -> case find keyEq (unMembers xs) of
142143
Just Member {value} -> Right (Key k ctx, value)
143144
Nothing -> Left (Errors.singleton (Error ("key not found: " <> k) ctx))
144145
where
145146
keyEq Member {key} = k == key
146147

147148
-- | An optional member. Returns Nothing if the value is missing.
148-
memberOpt :: ShortText -> Members ~> Maybe Value
149+
memberOpt :: Text -> Members ~> Maybe Value
149150
memberOpt k = P $ \ctx xs -> case find keyEq (unMembers xs) of
150151
Just Member {value} -> Right (Key k ctx, Just value)
151152
Nothing -> Right (ctx, Nothing)
@@ -248,15 +249,15 @@ instance ArrowChoice Parser where
248249
instance ArrowApply Parser where
249250
app = P $ \ctx (p, x) -> unParser p ctx x
250251

251-
fail :: ShortText -> a ~> b
252+
fail :: Text -> a ~> b
252253
fail msg = P $ \ctx _ -> Left (Errors.singleton (Error msg ctx))
253254

254255
failZero :: a ~> b
255256
failZero = P $ \ctx _ -> Left (Errors.singleton (Error "" ctx))
256257

257258
liftMaybe ::
258259
-- | Message to display on decode error
259-
ShortText ->
260+
Text ->
260261
-- | Decode function
261262
(a -> Maybe b) ->
262263
a ~> b

src/Json/Context.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Json.Context
1111
) where
1212

1313
import Data.Bytes.Builder (Builder)
14+
import Data.Text (Text)
1415
import Data.Text.Short (ShortText)
1516
import Json.Path (Path)
1617

@@ -26,7 +27,7 @@ parsing.
2627
-}
2728
data Context
2829
= Top
29-
| Key !ShortText !Context
30+
| Key {-# UNPACK #-} !Text !Context
3031
| Index !Int !Context
3132
deriving (Eq, Show)
3233

src/Json/Error.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Json.Error
1313
import Data.ByteString.Short.Internal (ShortByteString (SBS))
1414
import Data.Bytes.Builder (Builder)
1515
import Data.Text.Short (ShortText)
16+
import Data.Text (Text)
1617
import Json.Context (Context (..))
1718

1819
import qualified Data.Bytes.Builder as Builder
@@ -23,7 +24,7 @@ import qualified Json.Context as Context
2324

2425
-- | A single error message.
2526
data Error = Error
26-
{ message :: !ShortText
27+
{ message :: {-# UNPACK #-} !Text
2728
, context :: !Context
2829
}
2930
deriving (Eq, Show)
@@ -39,4 +40,4 @@ builderUtf8 :: Error -> Builder
3940
builderUtf8 Error {message, context} =
4041
Context.builderUtf8 context
4142
<> Builder.ascii2 ':' ' '
42-
<> Builder.shortTextUtf8 message
43+
<> Builder.textUtf8 message

src/Json/Parser.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import Data.Int (Int32)
5858
import Data.List (find)
5959
import Data.Number.Scientific (Scientific)
6060
import Data.Primitive (SmallArray)
61-
import Data.Text.Short (ShortText)
61+
import Data.Text (Text)
6262
import Data.Word (Word16, Word32, Word64)
6363
import Json (Member (Member), Value (Array, Number, Object))
6464

@@ -127,7 +127,7 @@ run (Parser f) = case f Top of
127127
Right a -> Right a
128128
Left e -> Left e
129129

130-
fail :: ShortText -> Parser a
130+
fail :: Text -> Parser a
131131
fail !msg = Parser (\e -> Left (Errors.singleton Error {context = e, message = msg}))
132132

133133
object :: Value -> Parser (SmallArray Member)
@@ -148,7 +148,7 @@ number = \case
148148
Number n -> pure n
149149
_ -> fail "expected number"
150150

151-
string :: Value -> Parser ShortText
151+
string :: Value -> Parser Text
152152
string = \case
153153
Json.String n -> pure n
154154
_ -> fail "expected string"
@@ -187,7 +187,7 @@ boolean = \case
187187
-- members :: Parser Value (Chunks Member)
188188
-- members = _
189189

190-
key :: ShortText -> (Value -> Parser a) -> MemberParser a
190+
key :: Text -> (Value -> Parser a) -> MemberParser a
191191
key !name f = MemberParser $ \p mbrs ->
192192
let !p' = Key name p
193193
in case find (\Member {key = k} -> k == name) mbrs of
@@ -199,7 +199,7 @@ callback if the key is not found. Using this parser combinators implies
199199
that there is no distinction between @null@ and an absent value in
200200
the encoding scheme.
201201
-}
202-
keyOptNull :: ShortText -> (Value -> Parser a) -> MemberParser a
202+
keyOptNull :: Text -> (Value -> Parser a) -> MemberParser a
203203
keyOptNull !name f = MemberParser $ \p mbrs ->
204204
let !p' = Key name p
205205
val = case find (\Member {key = k} -> k == name) mbrs of

src/Json/Path.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Data.ByteString.Short.Internal (ShortByteString (SBS))
2323
import Data.Bytes.Builder (Builder)
2424
import Data.Primitive (ByteArray (ByteArray))
2525
import Data.Text.Short (ShortText)
26+
import Data.Text (Text)
2627
import Json (Member (Member), Value (Array, Null, Object))
2728

2829
import qualified Data.Bytes.Builder as Builder
@@ -33,7 +34,7 @@ import qualified Data.Text.Short.Unsafe as TS
3334
-- | A path to an object.
3435
data Path
3536
= -- | JSON path element of a key into an object, \"object.key\".
36-
Key {-# UNPACK #-} !ShortText !Path
37+
Key {-# UNPACK #-} !Text !Path
3738
| -- | JSON path element of an index into an array, \"array[index]\".
3839
-- Negative numbers result in undefined behavior.
3940
Index {-# UNPACK #-} !Int !Path
@@ -51,7 +52,7 @@ builderUtf8 :: Path -> Builder
5152
builderUtf8 p0 = Builder.ascii '$' <> go p0
5253
where
5354
go Nil = mempty
54-
go (Key k p) = Builder.ascii '.' <> Builder.shortTextUtf8 k <> go p
55+
go (Key k p) = Builder.ascii '.' <> Builder.textUtf8 k <> go p
5556
go (Index i p) =
5657
Builder.ascii '['
5758
<> Builder.wordDec (fromIntegral i)

test/DogHouse.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Data.ByteString.Short.Internal (ShortByteString (SBS))
1515
import Data.Bytes (Bytes)
1616
import Data.Primitive (ByteArray, SmallArray)
1717
import Data.Text.Encoding (encodeUtf8)
18-
import Data.Text.Short (ShortText)
18+
import Data.Text (Text)
1919
import NeatInterpolation (text)
2020

2121
import qualified Data.ByteString.Short as SBS
@@ -24,13 +24,13 @@ import qualified Data.Primitive as PM
2424
import qualified GHC.Exts as Exts
2525

2626
data House = House
27-
{ address :: !ShortText
27+
{ address :: {-# UNPACK #-} !Text
2828
, dogs :: !(SmallArray Dog)
2929
}
3030
deriving (Eq, Show)
3131

3232
data Dog = Dog
33-
{ name :: !ShortText
33+
{ name :: {-# UNPACK #-} !Text
3434
, age :: !Int
3535
, alive :: !Bool
3636
}

0 commit comments

Comments
 (0)