Parsing a JSON post

yesod

Solution

Well, as it turn out, I needed to add a "toContent" call in there to convert from Text to Content. Here is a piece of code that works:

data Person = Person
              { person_firstName :: Text
              , person_lastName :: Text
              , person_fullName :: Text
              , person_friends :: [Friend]
              }

data Friend = Friend
              { friend_name :: Text
              , friend_inTwitter :: Bool
              , friend_twitterName :: Text
              }


$(deriveJSON (drop 7) ''Person)              
$(deriveJSON (drop 7) ''Friend)   


postKnockoutR :: Handler RepPlain
postKnockoutR = do
  value <- parseJsonBody_
  let (f:fs) = person_friends value
  return $ RepPlain $ toContent $ friend_name f

Problem

I have the following piece of code: ``` data Friend = Friend { friend_name :: Text , friend_inTwitter :: Bool , friend_twitterName :: Maybe Text } $(deriveJSON (drop 6) ''Friend) ``` This piece of JSON is being posted to a handler, and I'm having a difficult time getting it. I've tried different things, but let me just put one of them here to generate suggestions: ``` postTestR :: Handler RepPlain postTestR = do value <- parseJsonBody_ return $ RepPlain $ friend_name value ``` That doesn't work, and I can see that the types don't match, but I'm not sure what to replace it with. I would also like to see how I could parse a list friends that gets posted as JSON. Thanks!

Original source