Relative Content

Tag Archive for jsongo

How to convert JSON to a generic struct in Go using interface{} without getting a map[string]interface{}?

I’m trying to convert JSON to a generic struct in Go, where the struct can have fields with varied types. To handle different types of data, I’m using the interface{} type in the struct fields. However, I don’t know the exact structure of the JSON object that will be unmarshalled, so I need a flexible solution. When I unmarshal the JSON, I end up with a map[string]interface{}, but I want to get an object (struct).

Unmarshal array of Json objects into struct returns blank

I’ve searched quite a bit for my specific use case but haven’t a solution, so I thought I’d ask. I’m learning Go at the moment, creating a module. But having trouble unmarshaling a json file into a struct. The contents of the json file are to be used as settings for the Asynq server since they might change and I don’t want to hardcode them.

Json unmarshal – Go

Working on Json Unmarshal/marshal capabilities in Go-lang. Ran into the below exercise from Go playground link

golang custom request/response data fields GIN GORM

My background is python/django so in python we have serializer to decide which field should be proccessed from request body and which field should be return in response body
I can’t find something like this in golang/gin/gorm
and I see their are many people doesn’t recommend DTO (data transfer object).
so is their library or prefered pattern in go to serializer & deserialize data ?

Looping over JSON data in GO

Im trying to loop over JSON data which ive written, as a kind of json database system. Although it does write and read. I can’t seem to access the data it has readed properly