In typescript, its easy and concise
function jsonParse<T>(str: string): T {
return JSON.parse(str)
}
let obj = jsonParse<Bookmarks[]>(data)
In rescript this is the best I can come up with, but it seems really verbose, and the aggressive formatting isn’t helping. I’m not that familiar with functors, maybe stuff like this is what they are there for ¯\(ツ)/¯
module MakeJSONParser = (
M: {
type t
},
) => {
@scope("JSON") external parse: string => M.t = "parse"
let parse = msg => parse(msg)
}
module M = MakeJSONParser({
type t = array<Bookmarks.t>
})
let obj = M.parse(msg)