'Get data from the second JSON column

I have a JSON response. I need to parse it using PHP to output in the right place only the data from the second column (close) and the last (end). I previously parsed the answers in JSON, but here the data is separated by commas and this caused me difficulties. I will be grateful for any help in this matter)

{
"candles": {
    "metadata": {
        "open": {"type": "double"},
        "close": {"type": "double"},
        "high": {"type": "double"},
        "low": {"type": "double"},
        "value": {"type": "double"},
        "volume": {"type": "double"},
        "begin": {"type": "datetime", "bytes": 19, "max_size": 0},
        "end": {"type": "datetime", "bytes": 19, "max_size": 0}
    },
    "columns": ["open", "close", "high", "low", "value", "volume", "begin", "end"], 
    "data": [
        [1420, 1430.8, 1435, 1412, 1468004613.8, 1031760, "2021-04-21 00:00:00", "2021-04-21 23:59:59"],
        [1430.8, 1443.6, 1450, 1411.4, 1805714798.6, 1260392, "2021-04-22 00:00:00", "2021-04-22 23:59:59"],
        [1449.4, 1427.2, 1453, 1419.2, 1345626448.8, 941921, "2021-04-23 00:00:00", "2021-04-23 23:59:59"],
        [1428.6, 1408.8, 1433, 1402.4, 1797991005.6, 1272377, "2021-04-26 00:00:00", "2021-04-26 23:59:59"],
        [1413.4, 1406.4, 1427.8, 1400.6, 1956301672.2, 1383856, "2021-04-27 00:00:00", "2021-04-27 23:59:59"],
        [1410, 1395.8, 1411, 1376, 1803028517.8, 1296254, "2021-04-28 00:00:00", "2021-04-28 23:59:59"],
        [1405, 1401, 1419, 1381.8, 2038346551, 1458584, "2021-04-29 00:00:00", "2021-04-29 23:59:59"],
        [1404.8, 1358, 1408, 1353.2, 2178159392, 1588664, "2021-04-30 00:00:00", "2021-04-30 23:59:59"]
    ]
}}


Solution 1:[1]

after you convert the object to an object using json_decode

foreach ($candles->data as $row) {
    echo "close: " . $row[1] . "\n";
    echo "end: " . $row[count($row)-1] . "\n";

The code is very specific for the provided example and it works only if the "close" is always second, and "end" is always the last element.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SIR