Laravel Refactor JSON

  eloquent, laravel, laravel-4, laravel-5, php

Here’s my JSON and I want to refactor those JSON in laravel

[
    {
        "TIMESTAMP": "2021-06-09 13:13:26",
        "COL1": "10",
        "COL2": "20",
        "COL3": "30"
    },
    {
        "TIMESTAMP": "2021-06-22 13:13:26",
        "COL1": "20",
        "COL2": "30",
        "COL3": "40"
    },
    {
        "TIMESTAMP": "2021-06-21 13:13:26",
        "COL1": "1",
        "COL2": "2",
        "COL3": "3"
    },
    {
        "TIMESTAMP": "2021-06-20 13:13:26",
        "COL1": "40",
        "COL2": "50",
        "COL3": "60"
    }
]

I need to refactor the json According to the Column name like:

[
    {
      "TITLE":"COL1"
      "DATA":[10,20,1,40]
      
    },
    {
       "TITLE":"COL2"
      "DATA":[20,30,2,50]
      
    },
    {
      "TITLE":"COL3"
      "DATA":[30,40,3,60]
      
    },
]

I was tried but am unable to reach the expected output.. Help me out with this…Thanks in advance

Source: Laravel

Leave a Reply