I have these AWS Lambdas that return JSON. My unit tests validate usually a single property. However… even basic JSON requires the worst way of getting properties (see snippet below). I tried the whole thing["field"][0]
, but it doesn’t work because it’s Js.Json.t
, not an Object. I’m using Jzon.encodeWith
as the last line. Should I… be doing some other step to convert Js.Json.t
to Object
or something?
… and please judge me harshly on the below :
let result =
Js.Json.decodeObject(json)
->Js.Option.getExn
-> Js.Dict.get("loans")
->Js.Option.getExn
-> Js.Json.decodeArray
->Js.Option.getExn
-> Js.Array.unsafe_get(0)
-> Js.Json.decodeObject
-> Js.Option.getExn
-> Js.Dict.get("merchantDiscountRate")
-> Js.Option.getExn
-> Js.Json.decodeString
-> Js.Option.getExn
stringEqual(result, "0.7")