我知道我是否有带有特定已知字段的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