I want to prevent alphabetically reordering at Marshal. My script is below. {"key3": "value3", "key2": "value2", "key1": "value1"}
is reordered to {"key1":"value1","key2":"value2","key3":"value3"}
by Marshal. I thought this may be close issue. But I could not solve my issue. Is there way to solve this?
Script
package main
import (
"encoding/json"
"fmt"
)
func main() {
obj := `{"key3": "value3", "key2": "value2", "key1": "value1"}`
var o map[string]interface{}
json.Unmarshal([]byte(obj), &o)
fmt.Println(o)
r, _ := json.Marshal(o)
fmt.Println(string(r))
}
-
fmt.Println(o)
ismap[key3:value3 key2:value2 key1:value1]
. -
fmt.Println(string(r))
is{"key1":"value1","key2":"value2","key3":"value3"}
.
Thank you so much for your time. And I'm sorry for my immature question.