Skip to content

Instantly share code, notes, and snippets.

@Jawshua
Created November 7, 2018 10:36
Show Gist options
  • Save Jawshua/a221a3293215c1b9631f379a17542a6a to your computer and use it in GitHub Desktop.
Save Jawshua/a221a3293215c1b9631f379a17542a6a to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"github.com/tidwall/sjson"
)
func main() {
str := `C:\Windows\System32`
goMarshal := &map[string]string{
"path": str,
}
// Generate with standard lib
data, _ := json.Marshal(goMarshal)
fmt.Println("Go: ", string(data))
// Generate with sjson
strData, _ := sjson.Set("{}", "path", str)
fmt.Println("sjson:", strData)
// Attempt to unmarshal sjson data
var dummy interface{}
fmt.Println(json.Unmarshal([]byte(strData), &dummy))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment