File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ regardless.
8080
8181#### Anti-quotation
8282
83- You can escape regular ` Yojson ` expression within a payload using ` [%y json_expr] ` . You can use
83+ You can escape regular ` Yojson ` expressions within a payload using ` [%y json_expr] ` . You can use
8484this to insert variables in the payload. For example:
8585
8686``` ocaml
@@ -126,7 +126,9 @@ Also note that there is no limitation on nesting such patterns but you probably
126126that too much.
127127
128128This is provided mostly for convenience. If you want efficient code and/or to handle complex json
129- objects I recommend that you use ` ppx_deriving_yojson ` instead.
129+ objects I recommend that you use
130+ [ ` ppx_deriving_yojson ` ] ( https://github.com/ocaml-ppx/ppx_deriving_yojson ) or
131+ [ ` ppx_yojson_conv ` ] ( https://github.com/janestreet/ppx_yojson_conv ) instead.
130132
131133To clarify, the following code:
132134``` ocaml
@@ -141,3 +143,19 @@ let f = function
141143 | `Assoc [("b", `Bool true); ("a", `Int 1)]
142144 ) -> (1, true)
143145```
146+
147+ #### Anti-quotation
148+
149+ You can also escape regular ` Yojson ` patterns in ` ppx_yojson ` pattern extensions' payload
150+ using ` [%y? json_pat] ` . You can use it to further deconstruct a ` Yojson ` value. For example:
151+
152+ ``` ocaml
153+ let f = function
154+ | [%yojson? {a = [%y? `Int i]} -> i + 1
155+ ```
156+
157+ is expanded into:
158+ ``` ocaml
159+ let f = function
160+ | `Assoc [("a", `Int i)] -> i + 1
161+ ```
You can’t perform that action at this time.
0 commit comments