How Should I get The Output In Html table?

package main

import (

func Handle(w http.ResponseWriter,r *http.Request) {
const jsonStream= {"id": 1, "Name": "John", "Salary": 6000} {"id": 2, "Name": "Mark", "Salary": 7000} {"id": 3, "Name": "Sandy", "Salary": 8000} {"id": 4, "Name": "Holard","Salary": 2000}
type Employee struct {
id int json:"id"
Name string json:"name"
Salary int json:"salary"

dec := json.NewDecoder(strings.NewReader(jsonStream))
for {
    var emp Employee
    if err := dec.Decode(&emp); err == io.EOF {
    } else if err != nil {
    if emp.Salary>5000{
    	fmt.Fprintf(w," %d  %s  %d ",,emp.Name,emp.Salary)


func main(){

A readable version of the code can be found at:

To achive your goal, there are some options.

  1. use html/template
  2. Write your table headers on the stream before you enter the loop, write columns to the stream in the loop, and write the tables footer after the loop.


The first solution requires a little bit more of work, as it requires you to learn the template language as well, also you have to create a proper context to work with. But in the long term it will result in code that is easier to read, less cluttered and much easier to maintain.

1 Like

in the output Why I am Getting Zero inplace of id in the above program as specified %d ?
any suggestions

id is not an exposed field and therefore invisible to the reflection package, which is used by the json (un)marschaller to introspect the struct.

All fields that you want to use in JSON need to be exposed (begin with a capital letter).