I am receiving an array of json objects (example below). I need to loop through them and output the json objects individually. One of the values "MessageID" is a large number and when I run json_encode(), its getting encoded with scientific notation. That won't work for me because the number is a database key.
Here is my code:
<?php
$json = file_get_contents('php://input');
$events = json_decode($json);
foreach($events as $event){
$debug = var_export($event, true); //still see the whole number here!
$event_json = json_encode($event); //number is converted to scientific notation
//code to create records in database
}
?>
Example input json:
[{
"event": "open",
"time": 1433103519,
"MessageID": 19421777396190490,
"email": "api@mailjet.com",
"mj_campaign_id": 7173,
"mj_contact_id": 320,
"customcampaign": "",
"CustomID": "helloworld",
"Payload": "",
"ip": "127.0.0.1",
"geo": "US",
"agent": "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0"
}]
I tried inserting the following to change the number to a string but it had no effect.
$event["MessageID"]=(string)$event["MessageID"]
How would I convert the MessageID property to a string or is there another way to get this to output the same way it came in?