Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jbowman99's avatar

JSON array decode

Good Morning,

I have a JSON object cast to an array that i am sending in a post request to a URL. when the URL receives the post request i am

var_dump($_POST)

which gives me this:

array(1) { [0]=> string(2339) "{"nid":null,"vid":null,"uid":1,"created":1445347764,"changed":"","moderate":0,"sticky":0,"promote":1,"tnid":0,"translate":0,"teaser_include":1,"teaser_js":"","name":"digital.media","date":"","revision":0,"log":"","format":1,"path":"","pathauto_perform_alias":0,"saxo_import":1,"saxo_xml_version":1,"copyright":"News-Gazette","subject":"1010 area update","saxo_category":"Local","saxo_user":"Jeff D'Alessio","saxo_type":"Article","saxo_notes":null,"author":"Jeff D'Alessio","saxo_breaking_news":"false","saxo_comment_settings":"Read\/Write","saxo_premium_content":"Premium content","ap":false,"author_name":"The News-Gazette","body":"SADORUS \u00d1 Village officials are\n investigating the possibility of having a private company purchase\n Sadorus\u00d5 water system.\n During a presentation to the board this week,\n Illinois American Water\u00d5s Ron Smith said the company\u00d5s rates\n increase by an average of 3 percent annually. He explained that the Illinois\n Commerce Commission has to approve rate hikes and that it typically takes\n the agency 11 months to review the company\u00d5s finances, expenditures and\n investments.\n \u00d2We cannot willy-nilly raise our rates,\u00d3 Smith\n said.\n If Sadorus sells its water system to Illinois American, its\n approximately 190 customers would join a base of 300,000, according to\n Smith.\n With Illinois American, Sadorus customers could expect to pay $45 for\n 5,500 gallons of water in a month. Under Sadorus\u00d5 current rate\n structure, the cost for the same amount is about $50.\n The Sadorus water\n plant was built in the 1960s and was upgraded in the 1980s.\n \u00d2What\n happens when we put your perfectly good-tasting water in our 50-year-old\n system?\u00d3 Village President John Deedrick asked.\n Replied Smith:\n \u00d2Over time, we will be replacing your pipes. We\u00d5ll rebuild your\n system.\u00d3"}" }

i need to grab elements out of this array. When i try and

$story = json_decode($_POST);
var_dump($story);

is returning NULL? I am using curl to do my POST request, which will not let me send a JSON object so I am casting it as an array?

is there a better way of sending the JSON object post request to a URL? or a way to parse the array into JSON again?

thanks,

0 likes
2 replies
dennisvdv's avatar

You should probably do

$story = json_decode($_POST[0]);
var_dump($story);

You see, $_POST returns an array, not the JSON string self.

Please or to participate in this conversation.