{"id":15263,"date":"2016-11-18T16:15:45","date_gmt":"2016-11-18T14:15:45","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=15263"},"modified":"2018-01-09T10:06:40","modified_gmt":"2018-01-09T08:06:40","slug":"php-json-encode-and-decode-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/","title":{"rendered":"PHP Json Encode And Decode Example"},"content":{"rendered":"<p>Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language (the way objects are built in JavaScript).<br \/>\nIn this example we will create a simple or trivial web app that shows us how to manipulate Json with PHP( Encode and decode Json data with PHP ).<br \/>\nFor this example we will use:<\/p>\n<ul>\n<li>A computer with PHP &gt;= 5.5 installed<\/li>\n<li>notepad++<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;8njY7i2QRy6sg8pg&#8217;]<\/p>\n<h2>1. Getting Started<\/h2>\n<p>JSON (JavaScript Object Notation) is a data variable format that is both lightweight and human-readable. JSON can be handled on the client side with javascript, this makes it suitable for server side and client side communication. JSON is gradually replacing (or as replaced )XML for transferring data from server to client and has become popular with web developers. Technologies like AJAX, Google Map API ( and many more, too numerous to be mentioned here.) allows for data to be relayed back to the client in JSON.<br \/>\nJSON is built on two structures:<\/p>\n<ul>\n<li>A collection of name\/value pairs.<\/li>\n<li>An ordered list of values.<\/li>\n<\/ul>\n<p>The light-weight attribute or character of JSON makes it preferable to XML as it reduces bandwidth consumption and verbosity (less bytes are transmitted when data format is in JSON unlike XML which uses more bytes). JSON has its limitations, we can&#8217;t transfer natives data types like dates.<\/p>\n<p>We have to convert the date to a supported type like strings, integer or UNIX Timestamp. Data types that can be used with JSON are strings, integers, null, boolean, arrays and objects.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt; \r\n &lt;html lang=\"en\"&gt; \r\n &lt;head&gt;    \r\n &lt;title&gt;Example of JSON Format&lt;\/title&gt;     \r\n&lt;\/head&gt;\r\n &lt;body&gt;    \r\n &lt;h1&gt;\r\nExample of JSON Format\r\n  &lt;\/h1&gt;\r\n    \r\n\r\n\r\n{ \r\n  \"first name\": \"John\",\r\n  \"last name\": \"Smith\", \r\n  \"married\": \"Yes\",\r\n  \"Num Of children\": 1,\r\n  \"Sex\": \"MALE\",\r\n  \"address\": { \r\n\"street address\": \"21 2nd Avenue Street mushin\", \r\n\"city\": \"Barracks\", \r\n\"state\": \"BA\", \r\n\"postal code\": 20081\r\n}, \r\n\"phone numbers\": [ \r\n\"212 555-1234\", \r\n\"646 555-4567\" ] \r\n}\r\n\r\n  &lt;\/body&gt; \r\n&lt;\/html&gt;\r\n\r\n\r\n<\/pre>\n<p>An Example of JSON formatted text in an HTML document. Some characteristics of JSON are:<\/p>\n<ul>\n<li>It is language independent.<br \/>\n<b>Note: <\/b>JSON format is text only like its companion XML. Text can be read by any programming language.<\/li>\n<li>It is light weight<\/li>\n<li>It is self describing and very easy to understand.<\/li>\n<li>Compared to XML, JSON is faster and easier to implement.<\/li>\n<\/ul>\n<h3>1.1 JSON Encoding With PHP<\/h3>\n<p>To encode data into JSON in PHP we use the function below:<\/p>\n<pre class=\"brush:bash\">string json_encode ( mixed\r\n$value, int $options, int $depth]] )\r\n\r\n<\/pre>\n<p>This function call on any data will return an encoded JSON string on success and FALSE on failure.<br \/>\n<b>Note: <\/b> All string data must be UTF-8 encoded.<br \/>\n<code> $value <\/code> Represents the data to be encoded.<br \/>\n<code>$options<\/code> Represents bitmask consisting of<\/p>\n<ul>\n<li>JSON_HEX_QUOT<\/li>\n<li>JSON_HEX_TAG<\/li>\n<li>JSON_HEX_AMP<\/li>\n<li>JSON_HEX_APOS<\/li>\n<li>JSON_NUMERIC_CHECK<\/li>\n<li>JSON_PRETTY_PRINT<\/li>\n<li>JSON_UNESCAPED_SLASHES<\/li>\n<li>JSON_FORCE_OBJECT<\/li>\n<li>JSON_PRESERVE_ZERO_FRACTION<\/li>\n<li>JSON_UNESCAPED_UNICODE<\/li>\n<li>JSON_PARTIAL_OUTPUT_ON_ERROR.<\/li>\n<\/ul>\n<p>The behavior of these constants can be found <a href=\"http:\/\/php.net\/manual\/en\/json.constants.php\">here <\/a><\/p>\n<p><code> $depth <\/code> is the maximum depth and this value must be greater than zero.<br \/>\nLets look at a simple example<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:php\">&lt;!DOCTYPE html&gt; \r\n &lt;html lang=\"en\"&gt; \r\n &lt;head&gt;    \r\n &lt;title&gt;Example of JSON Format&lt;\/title&gt;     \r\n&lt;\/head&gt;\r\n &lt;body&gt;    \r\n &lt;h1&gt;\r\nExample of JSON Format\r\n  &lt;\/h1&gt;\r\n\r\n&lt;?php \r\n\r\n$lang= array(\"PHP\", \"Java\", \"JS\", \"HTML\", \"Perl\", \".NET\");\r\n\/\/ Returns [\"PHP\",\"Java\",\"JS\",\"HTML\",\"Perl\",\".NET\"]\r\necho json_encode($lang);\r\necho \"&lt;br&gt;\";\r\n\/\/[{\"php\":\"PHP\",\"Java\":\"JAVA\",\"HTML\":\"HTML\",\"perl\":\"PERL\",\"net\":\"NET\"}]\r\n$lang=array(array(\"php\" =&gt; \"PHP\", \"Java\" =&gt; \"JAVA\", \"HTML\" =&gt; \"HTML\", \"perl\" =&gt; \"PERL\", \"net\" =&gt; \"NET\"));\r\n echo json_encode($lang);\r\necho \"&lt;br&gt;\";\r\n\/\/ Returns: {\"apples\":true,\"bananas\":null}\r\n echo json_encode(array(\"PHP\" =&gt; true, \"JAVA\" =&gt; true, \" Perl\" =&gt; FALSE, \"Basic\" =&gt; null)); \r\n\r\n?&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>You can see that boolean and strings are not converted to strings, they are converted to the right types. Another Example Below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index2.php<\/em><\/span><\/p>\n<pre class=\"brush:php\">&lt;!DOCTYPE html&gt; \r\n &lt;html lang=\"en\"&gt; \r\n &lt;head&gt;    \r\n &lt;title&gt;Example of JSON Format&lt;\/title&gt;     \r\n&lt;\/head&gt;\r\n &lt;body&gt;    \r\n &lt;h1&gt;\r\nExample of JSON Format\r\n  &lt;\/h1&gt;\r\n\r\n&lt;?php \r\nclass lang {   \r\npublic $java = \"JAVA\";    \r\npublic $php  = \"PHP\";     \r\npublic $html = \"HTML\";\r\npublic $js = \"JAVASCRIPT\";\r\npublic $perl = \"PERL\";\r\npublic $dates = \"\";\r\n }\r\n$lan = new lang();\r\n$lan-&gt;dates = new DateTime();\r\n\r\n\/* Returns:    \r\n{\"java\":\"JAVA\",\"php\":\"PHP\",\"html\":\"HTML\",\"js\":\"JAVASCRIPT\",\"perl\":\"PERL\",\"dates\":{\"date\":\"2016-11-18 01:27:34.000000\",\"timezone_type\":3,\"timezone\":\"Asia\\\/Jakarta\"}}\r\n *\/\r\n\r\n echo json_encode($lan);\r\n\r\n\r\n ?&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>In the example script we actually print out the JSON value of an object. In PHP objects are inspected and their public attributes are converted.<\/p>\n<h3>1.2 JSON Decoding With PHP<\/h3>\n<p>Decoding JSON is as simple as encoding it. To decode JSON in PHP we use the function below:<\/p>\n<pre class=\"brush:bash\">mixed json_decode ( string\r\n$json, bool $asso )\r\n\r\n<\/pre>\n<p>This function takes a JSON encoded string and converts it into a PHP variable.\u00a0<code>$json<\/code> is the json string being decoded. This function only works with UTF-8 encoded strings.<br \/>\n<code> assoc <\/code> is a boolean variable when set to TRUE, returned objects will be converted into associative arrays.<br \/>\nThis function returns the value encoded in json in appropriate PHP type. Values true , false and null are returned as TRUE, FALSE and NULL respectively. NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index3.php<\/em><\/span><\/p>\n<pre class=\"brush:php\">&lt;!DOCTYPE html&gt; \r\n &lt;html lang=\"en\"&gt; \r\n &lt;head&gt;    \r\n &lt;title&gt;Example of JSON Format&lt;\/title&gt;     \r\n&lt;\/head&gt;\r\n &lt;body&gt;    \r\n &lt;h1&gt;\r\nExample of JSON Format\r\n  &lt;\/h1&gt;\r\n&lt;?php\r\n\/*the function call both returns\r\nobject(stdClass)#1 (5) { [\"a\"]=&gt; int(1) [\"b\"]=&gt; int(2) [\"c\"]=&gt; int(3) [\"d\"]=&gt; int(4) [\"e\"]=&gt; int(5) }\u00a0\r\narray(5) { [\"a\"]=&gt; int(1) [\"b\"]=&gt; int(2) [\"c\"]=&gt; int(3) [\"d\"]=&gt; int(4) [\"e\"]=&gt; int(5) }\r\n*\/\r\n\r\n$json = '{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5}' ;\r\nvar_dump (json_decode\r\n( $json));\r\n\r\necho \"&lt;br&gt;\";\r\n\r\nvar_dump (json_decode\r\n( $json, true));\r\n?&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>The above example decodes a JSON string into PHP variable. According to the official PHP website <code> var_dump<\/code> displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.<\/p>\n<p>All public, private and protected properties of objects will be returned in the output unless the object implements a <code>__debugInfo() <\/code>method (implemented in PHP 5.6.0).<\/p>\n<h2>2. Summary<\/h2>\n<p>In this tutorial we learnt about the nitty-gritty of json. We also learnt how to encode data to JSON and decide JSON into a PHP variable.<\/p>\n<h2>3. Download the source code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/11\/phpjsonencodeanddecode.zip\">phpjsonencodeanddecode<\/a><\/strong><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language (the way objects are built in JavaScript). In this example we will create a simple or trivial web app that shows us how to manipulate Json with &hellip;<\/p>\n","protected":false},"author":164,"featured_media":930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[405,404],"class_list":["post-15263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php-json-decode","tag-php-json-encode"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Json Encode And Decode Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Json Encode And Decode Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-18T14:15:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T08:06:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Olayemi Odunayo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Olayemi Odunayo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/\"},\"author\":{\"name\":\"Olayemi Odunayo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\"},\"headline\":\"PHP Json Encode And Decode Example\",\"datePublished\":\"2016-11-18T14:15:45+00:00\",\"dateModified\":\"2018-01-09T08:06:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/\"},\"wordCount\":725,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"keywords\":[\"PHP Json Decode\",\"Php json encode\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/\",\"name\":\"PHP Json Encode And Decode Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"datePublished\":\"2016-11-18T14:15:45+00:00\",\"dateModified\":\"2018-01-09T08:06:40+00:00\",\"description\":\"Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/php\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Json Encode And Decode Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\",\"name\":\"Olayemi Odunayo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"caption\":\"Olayemi Odunayo\"},\"description\":\"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.\",\"sameAs\":[\"https:\/\/www.webcodegeeks.com\/\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Json Encode And Decode Example - Web Code Geeks - 2026","description":"Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/","og_locale":"en_US","og_type":"article","og_title":"PHP Json Encode And Decode Example - Web Code Geeks - 2026","og_description":"Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of","og_url":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-11-18T14:15:45+00:00","article_modified_time":"2018-01-09T08:06:40+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","type":"image\/jpeg"}],"author":"Olayemi Odunayo","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Olayemi Odunayo","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/"},"author":{"name":"Olayemi Odunayo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8"},"headline":"PHP Json Encode And Decode Example","datePublished":"2016-11-18T14:15:45+00:00","dateModified":"2018-01-09T08:06:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/"},"wordCount":725,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","keywords":["PHP Json Decode","Php json encode"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/","url":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/","name":"PHP Json Encode And Decode Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","datePublished":"2016-11-18T14:15:45+00:00","dateModified":"2018-01-09T08:06:40+00:00","description":"Json is an abbreviation for JavaScript Object Notation. It is a lightweight format that is used for data interchanging. It is based on a subset of","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/php\/php-json-encode-and-decode-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"PHP","item":"https:\/\/www.webcodegeeks.com\/category\/php\/"},{"@type":"ListItem","position":3,"name":"PHP Json Encode And Decode Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8","name":"Olayemi Odunayo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","caption":"Olayemi Odunayo"},"description":"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.","sameAs":["https:\/\/www.webcodegeeks.com\/"],"url":"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/164"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=15263"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15263\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/930"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=15263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=15263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=15263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}