forked from mirror/gjson
mention GetBytes function
This commit is contained in:
parent
5fdbb97fe1
commit
95c6f92c50
15
README.md
15
README.md
|
@ -29,7 +29,7 @@ $ go get -u github.com/tidwall/gjson
|
|||
This will retrieve the library.
|
||||
|
||||
## Get a value
|
||||
Get searches json for the specified path. A path is in dot syntax, such as "name.last" or "age". This function expects that the json is well-formed and validates. Invalid json will not panic, but it may return back unexpected results. When the value is found it's returned immediately.
|
||||
Get searches json for the specified path. A path is in dot syntax, such as "name.last" or "age". This function expects that the json is well-formed and validates. Invalid json will not panic, but it may return back unexpected results. When the value is found it's returned immediately.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
@ -50,6 +50,9 @@ This will print:
|
|||
Prichard
|
||||
```
|
||||
|
||||
*There also the [GetBytes](#working-with-bytes) function when working with JSON byte slices.*
|
||||
|
||||
|
||||
## Path Syntax
|
||||
|
||||
A path is a series of keys separated by a dot.
|
||||
|
@ -214,6 +217,16 @@ if !ok{
|
|||
}
|
||||
```
|
||||
|
||||
## Working with Bytes
|
||||
|
||||
If your JSON is contained a `[]byte` slice, there's the [GetBytes](https://godoc.org/github.com/tidwall/gjson#GetBytes) function. This is preferred over `Get(string(data), path)`.
|
||||
|
||||
```go
|
||||
var data []byte = ...
|
||||
res := gjson.GetBytes(data, path)
|
||||
```
|
||||
|
||||
|
||||
## Performance
|
||||
|
||||
Benchmarks of GJSON alongside [encoding/json](https://golang.org/pkg/encoding/json/),
|
||||
|
|
Loading…
Reference in New Issue