Last active
July 29, 2017 04:51
-
-
Save cipepser/2bd83a17dba79bec793e5f07296e7b6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"gopkg.in/mgo.v2/bson" | |
) | |
func main() { | |
var b interface{} | |
j := []byte(`{"id": 0, "name": "Alice", "countory": "Japan"}`) | |
// transform json to bson | |
err := bson.UnmarshalJSON(j, &b) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(b) // map[countory:Japan id:0 name:Alice] | |
// transform bson to json | |
j2, err := bson.MarshalJSON(b) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(string(j2)) // {"countory":"Japan","id":0,"name":"Alice"} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment