From 95c6f92c50bdc0eafa0520282a724a2661c38b63 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Fri, 28 Oct 2016 09:07:48 -0700 Subject: [PATCH] mention GetBytes function --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 045e52b..297bd95 100644 --- a/README.md +++ b/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/),