{"id":1229,"date":"2014-04-06T09:37:46","date_gmt":"2014-04-06T09:37:46","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1229"},"modified":"2025-11-30T18:57:22","modified_gmt":"2025-11-30T18:57:22","slug":"convert-json-to-php-array","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/json\/convert-json-to-php-array","title":{"rendered":"json decode-convert to PHP array"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>  $DecodedJson = json_decode($JsonData, TRUE);\n  if (is_null($DecodedJson))\n    $DecodedJson = array();\n  \n  \/\/Check for an error occured\n  if (json_last_error() !== JSON_ERROR_NONE)\n    echo \"json_decode error\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Check for json values present<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $DecodedJson = json_decode($result, TRUE);\n  if (!is_null($DecodedJson))\n  {\n    if (isset($DecodedJson&#91;'data']))\n      echo $DecodedJson&#91;'data'];\n\n    if (isset($DecodedJson&#91;'result']&#91;0]&#91;'longitude']))\n      echo $DecodedJson&#91;'result']&#91;0]&#91;'longitude'];\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Reading json from a file<br> <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tif (is_file('found_wifi_networks.json'))\n\t{\n\t\t$file_contents = file_get_contents('found_wifi_networks.json');\n\t\t$decoded_json = json_decode($file_contents, TRUE);\n\t\tprint_r($decoded_json);\n\t\techo \"&lt;br \/&gt;&lt;br \/&gt;\";\n\t\t$results_count = count($decoded_json&#91;'FoundWiFiNetworks']);\n\t\tfor ($count = 0; $count &lt; $results_count; $count++)\n\t\t{\n\t\t\techo \"Result \" . ($count + 1) . \": \" . $decoded_json&#91;'FoundWiFiNetworks']&#91;$count]&#91;SSID] . \"&lt;br \/&gt;\";\n\t\t}\n\t\techo \"&lt;br \/&gt;&lt;br \/&gt;\";\n\t}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">json stored within json fields<\/h4>\n\n\n\n<p>When you decode remember that you will need to decode the nested json field as a separate decode operation, you won&#8217;t get a single array which automatically nests the sub json.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Check for json values present Reading json from a file json stored within json fields When you decode remember that you will need to decode the nested json field as a separate decode operation, you won&#8217;t get a single array which automatically nests the sub json.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[109],"tags":[],"class_list":["post-1229","post","type-post","status-publish","format-standard","hentry","category-json"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1229"}],"version-history":[{"count":15,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1229\/revisions"}],"predecessor-version":[{"id":5192,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1229\/revisions\/5192"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}