Q
Q
Qudres2017-10-23 12:33:44
go
Qudres, 2017-10-23 12:33:44

Is there a quick way to create structures for parsing JSON in Golang?

Often when working with some kind of API in the JSON response there are 20-30 different lines, given that there are most likely nested structures and fields of the SQL DATETIME type, then to parse one response, you need to describe 3-5 structures, and a good half an hour of hammering on the keyboard, and the IDE doesn't really help with that. Maybe someone knows an easy way to create structures from JSON?
PS I just started learning Go, but working with JSON is something that is required very often.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
amorphine, 2017-10-23
@Qudres

Maybe there are smarter things (through reflection), but I used this

D
danforth, 2017-10-24
@danforth

If you are working with JSON and you don't need some of the data, you can describe it as json.RawMessage. Sometimes, if the response from the server comes with a large nesting depth, and the part we need lies somewhere on the surface, we can get to it by describing the unnecessary parts as json.RawMessagea type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question