From 503f5cd847d935e7565907d05d8e44d07055f9e7 Mon Sep 17 00:00:00 2001 From: Andrey Popp <8mayday@gmail.com> Date: Fri, 6 Sep 2024 18:07:59 +0400 Subject: [PATCH] README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 00f111d..8238956 100644 --- a/README.md +++ b/README.md @@ -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]`