How to Parse a JSON File in PHP

In this lesson I will show you how you can parse a JSON file and retrieve information from the object.

Let us consider the following:

Lines 2 to 10: The JSON data should be quite easy to interpret.  We have the Make of a car (Porsche) and 3 models of the Porsche car (911, 911 Turbo, and Carrera).

Line 12: we decode the JSON data

Line 14: we retrieve the data in position 1 of the Model array.  In this case it is 911 Turbo.

The output is:

911 Turbo