2

I'm working on cargo wordpress plugin, the shipping history page stores the following data in meta_value field in database. Does anyone know what kind of data is this, and how should I use it or change to a JSON.

s:815:"a:4:{i:0;a:7:{s:4:"date";s:10:"2018-03-08";s:4:"time";s:7:"1:00 am";s:8:"location";s:4:"test";s:12:"updated-name";s:7:"wpcargo";s:10:"updated-by";i:2;s:7:"remarks";s:1:"1";s:6:"status";s:16:"Shipment Left US";}i:1;a:7:{s:4:"date";s:10:"2018-03-08";s:4:"time";s:7:"1:00 am";s:8:"location";s:4:"test";s:12:"updated-name";s:7:"wpcargo";s:10:"updated-by";i:2;s:7:"remarks";s:1:"1";s:6:"status";s:10:"Processing";}i:2;a:7:{s:4:"date";s:10:"2018-09-12";s:4:"time";s:7:"7:27 pm";s:8:"location";s:4:"test";s:12:"updated-name";s:7:"wpcargo";s:10:"updated-by";i:2;s:7:"remarks";s:1:"1";s:6:"status";s:10:"In Transit";}i:3;a:7:{s:4:"date";s:10:"2018-09-12";s:4:"time";s:7:"7:31 pm";s:8:"location";s:10:"tofindthis";s:12:"updated-name";s:7:"wpcargo";s:10:"updated-by";i:2;s:7:"remarks";s:1:"1";s:6:"status";s:10:"In Transit";}}";
Liang
  • 507
  • 2
  • 9

1 Answers1

2

That looks like a serialized array.

To convert it to JSON you need to deserialize it first and then json_encode it

How to use php serialize() and unserialize()

echo json_encode($arr);

will echo the json enconded string where $arr is the deserialized array.

Juan
  • 5,525
  • 2
  • 15
  • 26
  • 2
    Note that input string has been serialized twice: the a:4 part is the serialized array, but that's wrapped in an s:815. So you'll need to pass it through PHP's unserialize() twice to get the array you can then json_encode. – Rup Sep 12 '18 at 21:29
  • @Rup I tried. The second unserialize() caught an error. The first one was good – Liang Sep 12 '18 at 21:46
  • https://en.wikipedia.org/wiki/PHP_serialization_format – Simon Pham Sep 04 '20 at 04:41