How to parse JSON

Pre-requisites: Basic Understanding HTML and JQuery.

In this project,

  • We will use json_encode()  and json_decode() functions to parse JSON data.

 

parseJSON.php

 

Run parseJSON.php file in your browser to get the following output. URL may look like as follows:

 

 

 

Code Explanation of parseJSON.php

1.

$indexedArr = array(

"Asia""Africa""Australia""Europe""Antartica"

);

Declaring and initializing an indexed array.

2.

json_encode($indexedArr);

json_encode is used to encode a PHP array to JSON string.

3.

json_decode($json);

Json_decode is used to decode a JSON string into an array.

 

Summary

In this project, we have learned to parse a PHP array into a JSON string using json_encode function.

We have also learned to parse JSON string to a PHP array using json_decode function. This is how, we exchange data in a standard format.

It is a language independent data format, therefore it can be easily used with other programming languages as well.

Help Us to Improve our content

Let's Talk
Go back to Previous Course

© 2021 Lecturely.com. All rights reserved.

Lecturely.com – Imagined by Paras Jairath, Developed by P3 Multisolutions & Powered by Network Bulls.