local cjson = require "cjson"

-- Exemple de JSON
local json_str = [[
{
  "cod": "200",
  "message": 0,
  "cnt": 40,
  "list": [
    {
      "dt": 1718312400,
      "main": {
        "temp": 12.84,
        "feels_like": 12.61,
        "temp_min": 12.84,
        "temp_max": 13.87,
        "pressure": 1010,
        "sea_level": 1010,
        "grnd_level": 1004,
        "humidity": 93,
        "temp_kf": -1.03
      },
      "weather": [
        {
          "id": 500,
          "main": "Rain",
          "description": "légère pluie",
          "icon": "10n"
        }
      ],
      "clouds": {
        "all": 100
      },
      "wind": {
        "speed": 6.07,
        "deg": 200,
        "gust": 11.82
      },
      "visibility": 10000,
      "pop": 1,
      "rain": {
        "3h": 1.17
      },
      "sys": {
        "pod": "n"
      },
      "dt_txt": "2024-06-13 21:00:00"
    },
    {
      "dt": 1718323200,
      "main": {
        "temp": 14.27,
        "feels_like": 14.21,
        "temp_min": 14.27,
        "temp_max": 15.25,
        "pressure": 1009,
        "sea_level": 1009,
        "grnd_level": 1002,
        "humidity": 94,
        "temp_kf": -0.98
      },
      "weather": [
        {
          "id": 500,
          "main": "Rain",
          "description": "légère pluie",
          "icon": "10n"
        }
      ],
      "clouds": {
        "all": 100
      },
      "wind": {
        "speed": 5.33,
        "deg": 255,
        "gust": 9.41
      },
      "visibility": 10000,
      "pop": 1,
      "rain": {
        "3h": 0.18
      },
      "sys": {
        "pod": "n"
      },
      "dt_txt": "2024-06-14 00:00:00"
    },
    {
      "dt": 1718334000,
      "main": {
        "temp": 13.46,
        "feels_like": 13.37,
        "temp_min": 13.46,
        "temp_max": 13.46,
        "pressure": 1008,
        "sea_level": 1008,
        "grnd_level": 1002,
        "humidity": 96,
        "temp_kf": 0
      },
      "weather": [
        {
          "id": 500,
          "main": "Rain",
          "description": "légère pluie",
          "icon": "10n"
        }
      ],
      "clouds": {
        "all": 77
      },
      "wind": {
        "speed": 3.98,
        "deg": 240,
        "gust": 10.97
      },
      "visibility": 10000,
      "pop": 0.2,
      "rain": {
        "3h": 0.1
      },
      "sys": {
        "pod": "n"
      },
      "dt_txt": "2024-06-14 03:00:00"
    },
    ...
  ]
}
]]

-- Décoder le JSON
local data = cjson.decode(json_str)

-- Extraire les 6 premières valeurs du champ "all"
local cloud_values = {}
for i = 1, math.min(6, #data.list) do
    table.insert(cloud_values, data.list[i].clouds.all)
end

-- Afficher les valeurs extraites
for i, value in ipairs(cloud_values) do
    print("Cloud coverage for point " .. i .. ": " .. value)
end

