Go: Working with JSON

Go: Working with JSON

I thought I knew how to handle JSON in Go.. that is until I was traveling and didn’t have the internet.
So below are my notes on handling go, and hopefully it will stick in my long term memory a little better!

So what are the main things you need to know for handling JSON in Go? Well they would be:

  • Turning data into JSON
  • Taking JSON and extracting it into usable data.

TL;DR:

  • it was really about creating a struct…

Turning Data into JSON

The standard tutorials use a User. Easy enough to understand.

We create a struct that will be used as the “JSON structure”

type User struct {
	Name  string `json:"name"` 
	Email string `json:"email"` 

}

Then lets pretend we have some User data

name := "George"
email := "fake@gmail.com"

so now lets first instantiate a struct of User, using the dot notation:

var person User
person.Name = name
person.Email = Email

This creates a struct that looks like:

User{
    Name: "Alice", 
    Email: "alice@example.com"
}

Then we need to Marshal (convert to JSON bytes) the person struct!

data, err := json.Marshal(person)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

Which converts our data into JSON. Resulting in:

{"name":"George","email":"fake@gmail.com"}

To see the code all together. It is setup in the Go Playground here

2026

Back to Top ↑

2021

Connecting to an Amazon MySQL RDS database

7 minute read

I recently received my AWS Solutions Architect Associate Cert, and I inadvertently learned more about Ops and DevOps in respect to automation, deployment an...

Connect to Splunk with Python

10 minute read

This post will cover the following: Connecting to Splunk with the Python SDK, executing a search and receiving the results Connecting to Splunk without ...

Back to Top ↑

2020

Winlogbeat & ELK

5 minute read

TL;DR: Create Logstash conf.d file to allow Winlogbeat to be ingested into Logstash. Change Winlogbeat config file to use Logstash instead of Elasticsearch.

Golang and Windows Network Interfaces

3 minute read

I have been working on Windows and needed to connect to a Network Interface (NIC). I ran into problems, here is what I learned and hope it saves the same tro...

Tcpdump Notes

less than 1 minute read

I have been using tcpdump recently and wanted to note down some of the commands Y’know, for future reference.

Pivoting with SSH

less than 1 minute read

Today I was trouble shooting a machine at work. I did not have access via RDP or VNC, so I used SSH to forward my traffic to the host so I could access a URL.

GitHub Actions

5 minute read

I participated in a DevSecOps type workshop on Saturday (May 9th) in which we created some GitHub Actions. This is a post to solidify the learning and be a c...

Threat Defense Workshop

2 minute read

On April 25th I was fortunate enough to participate in the Trend Micro Threat Defense workshop.

Incident Handling Certification

11 minute read

Since I blogged about my experience at OpenSoc, I wanted to expand on the value I found in my eLearnSecuirty Incident Response course. What you will find bel...

OpenSoc Experience

5 minute read

So Thursday (April 9th) I participated in an online blue team defense simulation event, known as OpenSOC.

Golang Parsing Strings

5 minute read

I have been working with Golang strings and how to manipulate them. Working from other blogs posts I’ve found. When I sit down to code, I seem to forget ever...

Welcome to Jekyll!

less than 1 minute read

You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different wa...

This is from my Home PC

less than 1 minute read

Blog from home installed jekyll on home PC, pulled GH repo. done :) (not that easy)

Back to Top ↑