You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ The following table summarizes the correspondence between OCaml types and JSON v
77
77
|`Yojson.Safe.t`| any | Identity transformation |
78
78
|`unit`| Null ||
79
79
80
-
Variants (regular and polymorphic) are represented using arrays; the first element is a string with the name of the constructor, the rest are the arguments. Note that the implicit tuple in a polymorphic variant is flattened. For example:
80
+
By default, variants (regular and polymorphic) are represented using arrays; the first element is a string with the name of the constructor, the rest are the arguments. Note that the implicit tuple in a polymorphic variant is flattened. For example:
81
81
82
82
```ocaml
83
83
# type pvs = [ `A | `B of int | `C of int * string ] list [@@deriving yojson];;
@@ -97,7 +97,14 @@ Record variants are represented in the same way as if the nested structure was d
97
97
["X",{"v":0}]
98
98
```
99
99
100
-
Record variants are currently not supported for extensible variant types.
100
+
Alternative representations of variants can be chosen using the option `variants` (i.e. ``[@@deriving yojson { variants = `Adjacent ("tag", "contents") }]``). The following table lists the ones that are supported:
By default, objects are deserialized strictly; that is, all keys in the object have to correspond to fields of the record. Passing `strict = false` as an option to the deriver (i.e. `[@@deriving yojson { strict = false }]`) changes the behavior to ignore any unknown fields.
0 commit comments