Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp committed Sep 6, 2024
1 parent 9f283ca commit 503f5cd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,22 @@ let t = of_json (Json.parseOrRaise {|{"a": 42}|})
(* t = { a = 42; b = None; } *)
```

#### `[@json.drop_default]`: drop default values from JSON

When a field has `[@option]` attribute one can use `[@json.drop_default]`
attribute to make the generated `to_json` function to drop the field if it's
value is `None`:

```ocaml
type t = {
a: int;
b: string option [@json.option] [@json.drop_default];
} [@@deriving to_json]
let t = to_json { a = 1; b = None; }
(* {"a": 1} *)
```

#### `[@json.key "S"]`: customizing keys for record fields

You can specify custom keys for record fields using the `[@json.key E]`
Expand Down

0 comments on commit 503f5cd

Please sign in to comment.