Day 3

A Go Program to Filter JSON Data

Try it!



View the source code


package main

import (
 "fmt"
 "encoding/json"
 "net/http"
)

type data struct {
 Name string `json:"name"`
 Age int `json:"age"`
 Job string `json:"job_title"`
 Salary float64 `json:"salary"`
 Currency string `json:"currency"`
 EmploymentType string `json:"employment_type"`
 Skills []string `json:"skills"`
 IsRemote bool `json:"remote"`
}

func main() {
 url := "https://raw.githubusercontent.com/pymite6941/portfolio-website/main/assets/test-data/jobs.json"
 resp,err := http.Get(url)
 if err != nil {
  fmt.Println("Error fetching data:", err)
  return
 }
 defer resp.Body.Close()
 var jsonData []data
 err = json.NewDecoder(resp.Body).Decode(&jsonData)
 if err != nil {
  fmt.Println("Error decoding JSON:", err)
  return
 }
 fmt.Println("Data:")
 for _,d := range jsonData {
  fmt.Printf("Name: %s\n", d.Name)
  fmt.Printf("Age: %d\n", d.Age)
  fmt.Printf("Job Title: %s\n", d.Job)
  fmt.Printf("Salary: %.2f\n", d.Salary)
  fmt.Printf("Currency: %s\n", d.Currency)
  fmt.Printf("Employment Type: %s\n", d.EmploymentType)
  fmt.Printf("Skills: %v\n", d.Skills)
  fmt.Printf("Remote: %t\n", d.IsRemote)
 }
}

The test data is here if you want to view it.



Description


This is a Go program that I learned linear searching with Go in. I found this project quite useful and I may use it in my finance kit when I expand to encompass more of the backend.

Previous Day
Next Day