Skip to content

Commit b192d50

Browse files
committed
feat: add safe object encoder
1 parent f341eb4 commit b192d50

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

src/Json_Decode.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ let string: t<string>
2222

2323
let array: t<'a> => t<array<'a>>
2424
let list: t<'a> => t<list<'a>>
25+
let object: (fieldDecoders => 'a) => t<'a>
2526
let option: t<'a> => t<option<'a>>
2627

2728
let date: t<Js.Date.t>
@@ -31,7 +32,6 @@ let tuple3: (t<'a>, t<'b>, t<'c>) => t<('a, 'b, 'c)>
3132
let tuple4: (t<'a>, t<'b>, t<'c>, t<'d>) => t<('a, 'b, 'c, 'd)>
3233
let dict: t<'a> => t<Js.Dict.t<'a>>
3334
let field: (string, t<'a>) => t<'a>
34-
let object: (fieldDecoders => 'a) => t<'a>
3535

3636
let oneOf: array<t<'a>> => t<'a>
3737
let map: (t<'a>, (. 'a) => 'b) => t<'b>

src/Json_Encode.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ let list = (encode, l) =>
3333
fill(1, tl)->Composite.jsonArray
3434
}
3535

36+
let object = props => props->Js.Dict.fromArray->Composite.jsonDict
37+
3638
let option = (encode, opt) =>
3739
switch opt {
3840
| None => null

src/Json_Encode.resi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ external string: string => Js.Json.t = "%identity"
88
@val external null: Js.Json.t = "null"
99
let array: t<'a> => t<array<'a>>
1010
let list: t<'a> => t<list<'a>>
11+
let object: array<(string, Js.Json.t)> => Js.Json.t
1112
let option: t<'a> => t<option<'a>>
1213
let withDefault: (Js.Json.t, t<'a>, option<'a>) => Js.Json.t
1314

0 commit comments

Comments
 (0)