-2

I have following JSON format I am receiving. I want to decode that in PHP. But I am unable to find how can I get the data within DATA key in following format.

JSON:

firedAt => Thu, 05 Feb 2015 20:00:13 GMT
event => orderPaid
data => [
  {
    "id": 10263410,
    "total": 219.00,
    "shipping": 0.00,
    "status": {
      "id": 2578171,
      "title": "Betalning mottagen",
      "color": "#c0ffc0",
      "is_paid": true,
      "is_delivered": false,
      "is_active": true
    },
    "note": null,
    "order_id": 10187,
    "deleted": false,
    "updated": null,
    "created": "2015-02-05 21:33:18",
    "reminder_sent": false,
    "market": 10,
    "market_reference": "47335091",
    "new": true,
    "integration": 274029,
    "weight": "0",
    "deliver_date": null,
    "rows": [
      {
        "id": 9086694,
        "quantity": 1,
        "title": "Mobilskal 62613-BRU",
        "reference": "62613-BRU",
        "price": 219,
        "market_reference": "26971426",
        "tax": "25",
        "created": "2015-02-05 21:33:18",
        "product_id": null,
        "integration": 274021,
        "vat": 43.8
      }
    ],
    "customer": {
      "contact": {
        "id": 934714,
        "alias": "Jane Doe",
        "email": "jane@doe.com",
        "phone": "0812839183",
        "mobile": "0721231234"
      },
      "address": {
        "id": 934714,
        "first_name": "Jane",
        "last_name": "Doe Svensson",
        "address": "Kungsgatan 6",
        "address2": "",
        "zip": "37450",
        "city": "Asarum",
        "country": {
          "name": "Sverige",
          "code": "se"
        }
      },
      "invoice": {
        "id": 934714,
        "first_name": "Jane",
        "last_name": "Doe Svensson",
        "address": "Kungsgatan 6",
        "address2": "",
        "zip": "37450",
        "city": "Asarum",
        "country": {
          "name": "Sverige",
          "code": "se"
        }
      }
    },
    "history": [
      {
        "id": "4457827",
        "created": "2015-02-05 21:33:18",
        "message": "Ny orderrad: 1 st Mobilskal 62613-BRU"
      }
    ],
    "icon": [  
    ]
  }
]
halfer
  • 19,824
  • 17
  • 99
  • 186
eweb
  • 3
  • 5
  • 1
    Some of that's JSON, the first bit isn't, so that's not going to decode. – Jonnix Oct 27 '16 at 14:22
  • If you have a good JSON (no syntax errors) you can use this. json_decode($JSON, true); – Vincent Toonen Oct 27 '16 at 14:23
  • So there is no way to decode? – eweb Oct 27 '16 at 14:23
  • @VincentToonen Problem is I am unable to get data within DATA key. How can I find that? After that I can use json_decode. HEre is the link from where I am geting response: https://sello.io/en/developers/webhooks/ – eweb Oct 27 '16 at 14:25
  • You can not find it yet because its not valid json – Vincent Toonen Oct 27 '16 at 14:25
  • This is valid json. {"employees":[ {"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ]} – Vincent Toonen Oct 27 '16 at 14:26
  • This is a helpfull link : http://stackoverflow.com/questions/6107039/how-to-select-json-item-from-the-array – Vincent Toonen Oct 27 '16 at 14:27
  • maybe you can share the code that generates this information – RST Oct 27 '16 at 14:45
  • We would need to see how you are decoding this in order to work out what is wrong. Would you edit this question to include the full runnable code that you have? – halfer Oct 27 '16 at 16:37

1 Answers1

0
json_decode($JSON['data'], true);

OR

$array = json_decode('{
"id": 10263410,
"total": 219.00,
"shipping": 0.00,
"status": {
  "id": 2578171,
  "title": "Betalning mottagen",
  "color": "#c0ffc0",
  "is_paid": true,
  "is_delivered": false,
  "is_active": true
},
"note": null,
"order_id": 10187,
"deleted": false,
"updated": null,
"created": "2015-02-05 21:33:18",
"reminder_sent": false,
"market": 10,
"market_reference": "47335091",
"new": true,
"integration": 274029,
"weight": "0",
"deliver_date": null,
"rows": [
  {
    "id": 9086694,
    "quantity": 1,
    "title": "Mobilskal 62613-BRU",
    "reference": "62613-BRU",
    "price": 219,
    "market_reference": "26971426",
    "tax": "25",
    "created": "2015-02-05 21:33:18",
    "product_id": null,
    "integration": 274021,
    "vat": 43.8
  }
],
"customer": {
  "contact": {
    "id": 934714,
    "alias": "Jane Doe",
    "email": "jane@doe.com",
    "phone": "0812839183",
    "mobile": "0721231234"
  },
  "address": {
    "id": 934714,
    "first_name": "Jane",
    "last_name": "Doe Svensson",
    "address": "Kungsgatan 6",
    "address2": "",
    "zip": "37450",
    "city": "Asarum",
    "country": {
      "name": "Sverige",
      "code": "se"
    }
  },
  "invoice": {
    "id": 934714,
    "first_name": "Jane",
    "last_name": "Doe Svensson",
    "address": "Kungsgatan 6",
    "address2": "",
    "zip": "37450",
    "city": "Asarum",
    "country": {
      "name": "Sverige",
      "code": "se"
    }
  }
},
"history": [
  {
    "id": "4457827",
    "created": "2015-02-05 21:33:18",
    "message": "Ny orderrad: 1 st Mobilskal 62613-BRU"
  }
],
"icon": [  
]
}', true);
Deniz Aktürk
  • 362
  • 1
  • 9