0

How do I loop through this json with PHP and only extract/print the 3 digit numbers under "DataPoints"?

My goal is to at some point take those 3 digit numbers and then add them all up and get the average.

[
    {
        "MetricName": "payment_cnt.STATE.1s",
        "Tags": {
            "environment": "P",
            "pymtver": "2",
            "dataset": "tpv"
        },
        "DataPoints": [
            [
                1569711341,
                236
            ],
            [
                1569711342,
                205
            ],
            [
                1569711343,
                205
            ],
            ]
        ]
    }
]
Zach
  • 374
  • 3
  • 8
  • 2
    Your JSON is invalid (I presume it's a cut/paste and you removed part of it), once that is corrected this will work: https://3v4l.org/Le8EZ – Nick Sep 28 '19 at 23:25
  • Thanks Nick. You're right, I cut off the bottom of the JSON but your solution works for me. I was able to print 'MetricName' and 'Tag' but was struggling to loop through 'DataPoints'. Your solutions makes sense and I understand. Thanks again internet stranger! – Zach Sep 29 '19 at 00:57
  • 1
    No worries. I always like to offer a solution (or at least a good pointer to one) when I close a question as a dupe... – Nick Sep 29 '19 at 00:58

0 Answers0