Parsing JSON string into record in Haskell

前端 未结 5 2149
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 10:42

I\'m struggling to understand this (I\'m still a bit new to Haskell) but I\'m finding the documentation for the Text.JSON package to be a little confusing. Basicall

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 11:13

    I support the answer by @tibbe. However, I would like to add How you check put some default value in case, the argument misses in the JSON provided.

    In tibbe's answer you can do the following:

    Tweet <$> v .: "from_user"
          <*> v .:? "to_user_id"       .!= "some user here"
          <*> v .: "profile_image_url" .!= "url to image"
          <*> v .: "created_at"
          <*> v .: "id_str"             != 232131
          <*> v .: "source"
    

    this will the dafault parameters to be taken while parsing the JSON.

提交回复
热议问题