How To Parse JSON into HTML Table with PHP for Dummies

Pelin R. Kuran
Personal Work Revision
2 min readOct 20, 2020

--

Recently JSON data format is getting hits, because of its clarity on listing/ combining data in comparison to XML. I am not going to drawn you into explanations nor comparisons about JSON. If you want to learn more about details of JSON you may find some stuff here.

Let’s start!

1.Get JSON

First you need to get your JSON data, my JSON file was under users/pelin/services. You can use file_get_contents() to get your JSONs.

After that you need to parse it with json_decode().

$content will be used in loop in the upcoming lines.

2. Parse Into HTML Table

If you don’t know and don’t have any idea about how PHP and HTML work together, let me show you something:

You only write <!DOCTYPE html> into your php file, then ta da! You have HTML embedded PHP code. As you can see here, to create header cells of our table we need a loop. We can say, content is my JSON object and ths is its array typed parameter. Those parameters and names are of course unique to me, don’t try to see any in yours :).

Let’s fill the Table data. Here we have two loops, since my json data are arrays, your data may not be in array form then you don’t need to make this control.

Close your curly bracelets and then you are ready to go!

Have Fun!

P.S This is my first project based article so I hope you will be satisfied with the given information.

The best preparation for tomorrow is doing your best today. H. Jackson Brown, JR.

Pelin R. Kuran

Undergraduate Information Systems Engineer

--

--