From 9775a6052c76e71365286c399a90da8d6bf13876 Mon Sep 17 00:00:00 2001 From: Pradithya Aria Date: Thu, 21 Apr 2022 13:31:29 +0800 Subject: [PATCH 1/2] Update documentation --- jsonpath.go | 6 ++++++ readme.md | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/jsonpath.go b/jsonpath.go index e3da86f..efb707d 100644 --- a/jsonpath.go +++ b/jsonpath.go @@ -13,6 +13,7 @@ import ( var ErrGetFromNullObj = errors.New("get attribute from null object") +// JosnPathLookup compile a jsonpath `jpath` and perform lookup on `obj` func JsonPathLookup(obj interface{}, jpath string) (interface{}, error) { c, err := Compile(jpath) if err != nil { @@ -21,6 +22,7 @@ func JsonPathLookup(obj interface{}, jpath string) (interface{}, error) { return c.Lookup(obj) } +// Compiled is a compiled jsonpath representation type Compiled struct { path string steps []step @@ -32,6 +34,7 @@ type step struct { args interface{} } +// MustCompile will compile a json path `jpath` and panic if compilation failed func MustCompile(jpath string) *Compiled { c, err := Compile(jpath) if err != nil { @@ -40,6 +43,7 @@ func MustCompile(jpath string) *Compiled { return c } +// Compile compile a jsonpath `jpath` and return the compiled version of the jsonpath or error func Compile(jpath string) (*Compiled, error) { tokens, err := tokenize(jpath) if err != nil { @@ -63,10 +67,12 @@ func Compile(jpath string) (*Compiled, error) { return &res, nil } +// String return string representation of the compiled jsonpath func (c *Compiled) String() string { return fmt.Sprintf("Compiled lookup: %s", c.path) } +// Lookup perform lookup using the compiled jsonpath on json `obj` func (c *Compiled) Lookup(obj interface{}) (interface{}, error) { var err error for _, s := range c.steps { diff --git a/readme.md b/readme.md index a8ee2db..0984682 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ A golang implementation of JsonPath syntax. follow the majority rules in http://goessner.net/articles/JsonPath/ but also with some minor differences. -this library is till bleeding edge, so use it at your own risk. :D +This library is forked from https://github.com/oliveagle/jsonpath with additional bugfixes and features. **Golang Version Required**: 1.5+ @@ -15,7 +15,7 @@ Get Started ------------ ```bash -go get github.com/oliveagle/jsonpath +go get github.com/gojekfarm/jsonpath ``` example code: @@ -111,4 +111,4 @@ example json path syntax. | $.store.book[:].price | [8.9.5, 12.99, 8.9.9, 22.99] | | $.store.book[?(@.author =~ /(?i).*REES/)].author | "Nigel Rees" | -> Note: golang support regular expression flags in form of `(?imsU)pattern` \ No newline at end of file +> Note: golang support regular expression flags in form of `(?imsU)pattern` From 7da2198522e3aeaea016840e96b474de46f60100 Mon Sep 17 00:00:00 2001 From: Pradithya Aria Date: Thu, 21 Apr 2022 13:33:46 +0800 Subject: [PATCH 2/2] Add golang 1.18 to ci --- .github/workflows/jsonpath.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jsonpath.yaml b/.github/workflows/jsonpath.yaml index 32094ab..17c7b10 100644 --- a/.github/workflows/jsonpath.yaml +++ b/.github/workflows/jsonpath.yaml @@ -12,7 +12,7 @@ jobs: name: Go ${{ matrix.go }} test strategy: matrix: - go: ["1.16", "1.17"] + go: ["1.16", "1.17", "1.18"] steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2