jeudi 17 juin 2021

Refactoring of Json in laravel

Alright, I need some assistance from an expert.

I have attached my Json below[

    {
        "ID": 1,
        "SOURCEID": 1,
        "TIMESTAMP": "2020-04-05 07:05:29",
        "VALUE": "30"
    },
    {
        "ID": 4,
        "SOURCEID": 2,
        "TIMESTAMP": "2020-04-05 07:05:17",
        "VALUE": "40"
    },
    {
        "ID": 3,
        "SOURCEID": 1,
        "TIMESTAMP": "2020-04-06 12:04:59",
        "VALUE": "35"
    },
    {
        "ID": 5,
        "SOURCEID": 1,
        "TIMESTAMP": "2020-06-17 12:01:32",
        "VALUE": "1"
    },
    {
        "ID": 6,
        "SOURCEID": 2,
        "TIMESTAMP": "2021-06-17 13:55:29",
        "VALUE": "2"
    }
]

I need to refactor the json like

  1. I need Unique time stamp in separate array like [2020-04-05,2020-04-06,2020-06-17,2021-06-17]

  2. I need json to be refactor based on timestamp and source id and json is dynamic like number of source id present in the given json there are two id that is 1 and 2. Below I gave expected output.

    { "sourceid: 1, "data":[30,35,1,0], }, { "sourceid": 2, "data":[40,0,0,2], }

Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3ztyfFY
via IFTTT

Aucun commentaire:

Enregistrer un commentaire