You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. # fastjson: optimized standard library JSON for Go
  2. `fastjson` has the same API as json from standard library `encoding/json`.
  3. The `Unmarshal` and `Decode` functions are faster, but everything else is the same as `encoding/json`
  4. ## Getting Started
  5. ```
  6. $go get github.com/intel-go/fastjson
  7. ```
  8. ##Perfomance
  9. The performance depends on the content of your json structures, not the structure you parse to.
  10. If `.json` has a lot of strings or numbers, fastjson is significantly faster than `encoding/json`
  11. ##Example
  12. ```Go
  13. import (
  14. "github.com/intel-go/fastjson"
  15. "fmt"
  16. )
  17. func main() {
  18. var jsonBlob = []byte(`[
  19. {"Name": "Platypus", "Order": "Monotremata"},
  20. {"Name": "Quoll", "Order": "Dasyuromorphia"}
  21. ]`)
  22. type Animal struct {
  23. Name string
  24. Order string
  25. }
  26. var animals []Animal
  27. err := fastjson.Unmarshal(jsonBlob, &animals)
  28. if err != nil {
  29. fmt.Println("error:", err)
  30. }
  31. fmt.Printf("%+v", animals)
  32. // Output:
  33. // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}]
  34. }
  35. ```
  36. ##API
  37. API is the same as encoding/json
  38. [GoDoc](https://golang.org/pkg/encoding/json/#Unmarshal)