How to parse incoming POST in laravel json array containing object

tjyoung
tjyoung used Ask the Experts™
on
I've been trying to parse an incoming POST that is as below in Laravel. Its apparently a json array containing an object.
Tried a number of things like json_decode and so on

How in laravel would I receive the incoming POST and say get at the account_id for example??
{
"deltas": [{
"date": 1577127539, 
"object": "message", 
"type": "message.created", 
"object_data": {
"namespace_id": "93d6z2qmxm050zh2znnp90afs", 
"account_id": "93d6z2qmxm050zh2znnp90afs", 
"object": "message", 
"attributes": {
"thread_id": "6ejmdhd2p0iyhscfac214xins", 
"received_date": 1577127517}, 
"id": "ioe47mlrjm592gbrc01c2tks", "metadata": null
}
}]
}

Open in new window

Thanks in advance for any help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
in general:

$tmp = '{
	"deltas": [
		{
			"date": 1577127539,
			"object": "message",
			"type": "message.created",
			"object_data": {
				"namespace_id": "93d6z2qmxm050zh2znnp90afs",
				"account_id": "93d6z2qmxm050zh2znnp90afs",
				"object": "message",
				"attributes": {
					"thread_id": "6ejmdhd2p0iyhscfac214xins",
					"received_date": 1577127517
				},
				"id": "ioe47mlrjm592gbrc01c2tks",
				"metadata": null
			}
		}
	]
}';

$json = json_decode($tmp, true);

$account_id = $json['deltas'][0]['object_data']['account_id'];

echo "account_id = ".$account_id;

Open in new window


change the $tmp to below for your post data:

$tmp = $_POST['yourData'];

Open in new window

Author

Commented:
Thank you Ryan... I was so close but yet so far lol

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial