parseJSON parse the complex JSON formats or files.
To parse json file in php following are the steps used in parseJSON.php file:
- Read the JSON file using file_get_contents();
- Decode the JSON file using json_decode(); Use two parameters in this method first to pass json file data and second to pass TRUE to convert decoded json into associative array.
- Now use foreach loop to traverse the JSON decoded array's elements. Use foreach($json_array as $objects){} to traverse a JSON array and use foreach($objects as $key => $value){} to traverse a JSON object.
- Echo the traversed elements.
parseJSON include following files:
- data.json
- parseJSON.php
- README.md
- LICENSE