File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ module JSONPointer.Model
3
3
, run
4
4
, atIndexOrKey
5
5
, atKey
6
+ , escapeKey
7
+ , unescapeKey
6
8
)
7
9
where
8
10
@@ -26,7 +28,7 @@ instance Monoid JSONPointer where
26
28
27
29
instance Show JSONPointer where
28
30
showsPrec _ (JSONPointer impl) =
29
- appEndo $ impl (\ _ text -> Endo (showString " /" . showString (T. unpack text)))
31
+ appEndo $ impl (\ _ text -> Endo (showString " /" . showString (T. unpack $ escapeKey text)))
30
32
31
33
instance Eq JSONPointer where
32
34
a == b = show a == show b
@@ -53,3 +55,15 @@ atIndexOrKey index key = JSONPointer $ \handler -> handler index key
53
55
{-# INLINE atKey #-}
54
56
atKey :: T. Text -> JSONPointer
55
57
atKey = atIndexOrKey Nothing
58
+
59
+ -- |
60
+ -- Escape JSON Pointer string.
61
+ -- See here https://datatracker.ietf.org/doc/html/rfc6901 for more details.
62
+ escapeKey :: T. Text -> T. Text
63
+ escapeKey = T. replace " /" " ~1" . T. replace " ~" " ~0"
64
+
65
+ -- |
66
+ -- Unscape JSON Pointer string.
67
+ -- See here https://datatracker.ietf.org/doc/html/rfc6901 for more details.
68
+ unescapeKey :: T. Text -> T. Text
69
+ unescapeKey = T. replace " ~0" " ~" . T. replace " ~1" " /"
You can’t perform that action at this time.
0 commit comments