How to define order while Unmarshalling json into Empty interface?

Viewed 41

I have JSON response from an API. When i try to Unmarshal it into an Empty interface (var sample interface{} )the order becomes random and not according to the Query. Is there any way to maintain the same order as the response?

1 Answers

No.

Note that JSON objects (the {...} things) are unordered as are maps in Go, so the question as is doesn't make much sense as there is no order to preserve.

Also note that JSON arrays (the [...] things) are orderer and their order will be preserved when unmarshaling to a slice.

Related