I am parsing json file this is my file :

```
        var jsonCode =
     """
     [
     {
       "productName": "Scrap",
       "prices": [
         {
           "priceName": "HMS I/II 80:20, CFR Turkey, $/mt",
           "minMaxPrice": "$ 325.0 - 330.0",
           "dailyAvgPrice": "$ 327.5",
           "dailyChangePercentage": "0.0",
           "fullName": "Scrap - HMS I/II 80:20, CFR Turkey, $/mt"
         },
         {
           "priceName": "Shredded, CFR Turkey, $/mt",
           "minMaxPrice": "$ 330.0 - 335.0",
           "dailyAvgPrice": "$ 332.5",
           "dailyChangePercentage": "0.0",
           "fullName": "Scrap - Shredded, CFR Turkey, $/mt"
         }
       ]
     },
     {
       "productName": "Alloy",
       "prices": [
         {
           "priceName": "Nickel, $/mt",
           "minMaxPrice": "$ 15690.0 - null",
           "dailyAvgPrice": "$ 15690.0",
           "dailyChangePercentage": "-0.35",
           "fullName": "Alloy - Nickel, $/mt"
         }
       ]
     }
     ]
     """

```

and I create struct for take json data. This is my struct :

```
import Foundation

// MARK: - ProductElement
struct Product: Codable {
    let productName: String
    let prices: [Price]
}
// MARK: - Price
struct Price: Codable {
    let priceName: String?
    let minMaxPrice, dailyAvgPrice, dailyChangePercentage, fullName: String

}

```

I need to at these in tableView so I create these variables

```
var fetchedPrices = [Product]()//This is the array which I decode my json
 var sections = [String]() //This is for tableView Sections
 var itemsInSection = [[Price]]() // This is for section items

```

I try to decode like this :

```
 sections = []
            let jsonData = jsonCode.data(using: .utf8)!
            self.fetchedPrices = try! JSONDecoder().decode([Product].self, from: jsonData)
            self.fetchedPrices.forEach { (Product) in
                self.sections.append(Product.productName)

                    Product.prices.forEach { (priceInfo) in

                    self.itemsInSection.append([priceInfo])

                }

            self.tableView.reloadData()
        }

```

and this is my all tableView methods :

```
 func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {

        return sections[section]
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return sections.count
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return itemsInSection[section].count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "priceCell",for: indexPath) as! priceListCellTableViewCell
        print(itemsInSection[indexPath.section][indexPath.row])
        print(itemsInSection.count)

```

// This is the output of print statements.
//Price(priceName: Optional("Shredded, CFR Turkey, $/mt"), minMaxPrice: "$ 330.0 - 335.0", dailyAvgPrice: "$ 332.5", dailyChangePercentage: "0.0", fullName: "Scrap - Shredded, CFR Turkey, $/mt")
3

```
        cell.cellHeader.text =  itemsInSection[indexPath.section][indexPath.row].priceName
        cell.dailyChange.text = itemsInSection[indexPath.section][indexPath.row].dailyChangePercentage
        cell.minMaxPrice.text = itemsInSection[indexPath.section][indexPath.row].minMaxPrice
        cell.dailyAvgPrice.text = itemsInSection[indexPath.section][indexPath.row].dailyAvgPrice

        return cell

    }

```

Why I can't add items in specific sections ? It looks like this :
[enter image description here](https://i.stack.imgur.com/kjMa6.png)