Make sure to add encodable like this
struct modelName : Encodsble
let categories = categoriesArray.map{ $0.toDictionary() }
extension Encodable {
func toDictionary() -> [String: Any] {
let mirror = Mirror(reflecting: self)
var dictionary = [String: Any]()
for child in mirror.children {
guard let label = child.label else {
continue
}
dictionary[label] = child.value
}
return dictionary
}
}