jsonhaskellaeson

Haskell Aeson how to parse key with list value?


if i parse "exchangeAgreements" with

fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("exchangeAgreements" :: Data.Text.Text)) myobject) :: Object

it returns an exchangeAgreements as an Object just fine

but if i do

fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("accounts" :: Data.Text.Text)) myobject) :: Object

it returns Nothing

{
  "exchangeAgreements": {
    "NYSE_EXCHANGE_AGREEMENT": "ACCEPTED",
    "NASDAQ_EXCHANGE_AGREEMENT": "ACCEPTED",
    "OPRA_EXCHANGE_AGREEMENT": "ACCEPTED"
  },
  "accounts": [
    {
      "accountId": "123",
      "displayName": "myname",
      "accountCdDomainId": "12345",
      "company": "AMER",
      "segment": "ADVNCED",
      "acl": "ABCD123",
      "authorizations": {
        "apex": false,
        "levelTwoQuotes": false,
        "stockTrading": true,
        "marginTrading": true,
        "streamingNews": false,
        "optionTradingLevel": "COVERED",
        "streamerAccess": true,
        "advancedMargin": true,
        "scottradeAccount": false
      }
    }
  ]
}

What do i need to do differently to be able to parse "accounts"?


Solution

  • I realized i just need to put [Object] instead of Object as a type

    fromJust (Data.Aeson.Types.parseMaybe (\o -> o .: ("accounts" :: Data.Text.Text)) myobject) :: [Object]