如何将 Data.Argonaut.Decode 模块与 JSON 一起用于任何字段?

How to use Data.Argonaut.Decode module with JSON with any field?

我知道我是否 JSON 具有特定的已知字段,例如“日期”和“标题”

{
  "date": "any string",
  "title": "any string"
}

然后,我可以通过定义

来解码它
myDecodeFunc :: Json -> Either JsonDecodeError ({ date :: String, title :: String })

myDecodeFunc = decodeJson

但是,我似乎找不到如何用这样的任意字段解码相同的 JSON。

{
  "any field": "any string",
  "any field": "any string"
}

我是 Purescript 的新手,如有任何指点,我们将不胜感激。谢谢。

对于您事先不知道所有可能字段的“记录”类事物的奇特术语是 字典

并且要将 JSON 解析为字典,请使用类似字典的类型,例如 Foreign.Object,它恰好有一个方便的 FromJSON 实例:

import Foreign.Object (Object)

myDecodeFunc :: Json -> Either JsonDecodeError (Object String)
myDecodeFunc = decodeJson