ChatGPT to process REST Responses in Golang

ChatGPT to process REST Responses in Golang

a picture of a cartoon character on a wall

Photo by Chinmay B on Unsplash

Working with Golang can be a pain sometimes, especially when you are new and don’t yet appreciate its beauty. A trivial task like processing a JSON response object - which is way easier in JS, to a point where you don’t even have to care about using variables to hold those values - in Golang, becomes too complicated.

But trusting the process and the wise words spoken around, if you be patient and just continue with the tedious process, there will come a point where you would love doing it in Golang. In this post, I help relieve some of that pain.

What’s the deal with JSON and Golang?

JSONs are the top-most universal standards defined for communication of text based information across tools, interfaces, and SaaS-based services. It enjoys inherent support in all the major programming languages today - arguably except Golang.

This caused headaches for me for a few weeks, until the requirements forced it down my throat - a hard pill to swallow. Especially, coming from a JS background, I found it absolutely useless to do so much of wiring just to process a simple JSON - forget about the nested ones.

How we do it in JS?

Its a joke - and I say this with a sense of appreciation. It is way too easy to access attributes or loop over a JSON object for processing. Let us consider a simple JSON object that looks like below.

{ "name": "value", "env" : "production" }

We can simply access name and env values by doing this:

var jsonObj =