-1

Hi I have a JSON that is in the given format

"exclusions": [
    [
      {
        "facility_id": "1",
        "options_id": "4"
      },
      {
        "facility_id": "2",
        "options_id": "6"
      }
    ],
    [
      {
        "facility_id": "1",
        "options_id": "3"
      },
      {
        "facility_id": "3",
        "options_id": "12"
      }
    ],
    [
      {
        "facility_id": "2",
        "options_id": "7"
      },
      {
        "facility_id": "3",
        "options_id": "12"
      }
    ]
  ]

I am using Object Mapper library to parse the JSON but from my knowledge , I feel it is missing a key, as each object under the key exclusions is an array, Is there anyway I can parse this using ObjectMapper

Avinash Sharma
  • 665
  • 1
  • 7
  • 23

1 Answers1

1

And why not Codable

class Root:Codable {
  let exclusions:[[InnerItem]]
}
class InnerItem:Codable {
   let facilityId:String
   let optionsId:String
  private enum CodingKeys: String, CodingKey {
     case facilityId = "facility_id"
     case optionsId = "options_id"
  }
}

//

do {
     let decoded = try JSONDecoder().decode(Root.self, from:jsonData)
     print(decoded)
} catch {
    print(error)
}

BTW your json needs a surrounding {}

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87