Compare commits

...

3 Commits

Author SHA1 Message Date
Andreas Deininger c53b0fe5c3
Merge 360c8e1074 into bbf40bb0e4 2024-02-15 03:09:42 -08:00
tidwall bbf40bb0e4 Fix backspace and form-feed for Go 1.22 2024-02-14 20:51:40 -07:00
Andreas Deininger 360c8e1074 Fixing typos 2023-11-17 10:09:45 +01:00
3 changed files with 19 additions and 15 deletions

View File

@ -1,6 +1,6 @@
# GJSON Path Syntax # GJSON Path Syntax
A GJSON Path is a text string syntax that describes a search pattern for quickly retreiving values from a JSON payload. A GJSON Path is a text string syntax that describes a search pattern for quickly retrieving values from a JSON payload.
This document is designed to explain the structure of a GJSON Path through examples. This document is designed to explain the structure of a GJSON Path through examples.
@ -15,12 +15,12 @@ This document is designed to explain the structure of a GJSON Path through examp
- [Multipaths](#multipaths) - [Multipaths](#multipaths)
- [Literals](#literals) - [Literals](#literals)
The definitive implemenation is [github.com/tidwall/gjson](https://github.com/tidwall/gjson). The definitive implementation is [github.com/tidwall/gjson](https://github.com/tidwall/gjson).
Use the [GJSON Playground](https://gjson.dev) to experiment with the syntax online. Use the [GJSON Playground](https://gjson.dev) to experiment with the syntax online.
## Path structure ## Path structure
A GJSON Path is intended to be easily expressed as a series of components seperated by a `.` character. A GJSON Path is intended to be easily expressed as a series of components separated by a `.` character.
Along with `.` character, there are a few more that have special meaning, including `|`, `#`, `@`, `\`, `*`, `!`, and `?`. Along with `.` character, there are a few more that have special meaning, including `|`, `#`, `@`, `\`, `*`, `!`, and `?`.
@ -46,7 +46,7 @@ The following GJSON Paths evaluate to the accompanying values.
### Basic ### Basic
In many cases you'll just want to retreive values by object name or array index. In many cases you'll just want to retrieve values by object name or array index.
```go ```go
name.last "Anderson" name.last "Anderson"

View File

@ -1252,7 +1252,7 @@ func parseObject(c *parseContext, i int, path string) (int, bool) {
} }
// matchLimit will limit the complexity of the match operation to avoid ReDos // matchLimit will limit the complexity of the match operation to avoid ReDos
// attacks from arbritary inputs. // attacks from arbitrary inputs.
// See the github.com/tidwall/match.MatchLimit function for more information. // See the github.com/tidwall/match.MatchLimit function for more information.
func matchLimit(str, pattern string) bool { func matchLimit(str, pattern string) bool {
matched, _ := match.MatchLimit(str, pattern, 10000) matched, _ := match.MatchLimit(str, pattern, 10000)
@ -2193,8 +2193,8 @@ func unescape(json string) string {
return string(str) return string(str)
} }
// Less return true if a token is less than another token. // Less returns true if a token is less than another token.
// The caseSensitive paramater is used when the tokens are Strings. // The caseSensitive parameter is used when the tokens are Strings.
// The order when comparing two different type is: // The order when comparing two different type is:
// //
// Null < False < Number < String < True < JSON // Null < False < Number < String < True < JSON

View File

@ -2578,6 +2578,9 @@ func TestJSONString(t *testing.T) {
testJSONString(t, s) testJSONString(t, s)
testJSONString(t, "R\xfd\xfc\a!\x82eO\x16?_\x0f\x9ab\x1dr") testJSONString(t, "R\xfd\xfc\a!\x82eO\x16?_\x0f\x9ab\x1dr")
testJSONString(t, "_\xb9\v\xad\xb3|X!\xb6\xd9U&\xa4\x1a\x95\x04") testJSONString(t, "_\xb9\v\xad\xb3|X!\xb6\xd9U&\xa4\x1a\x95\x04")
data, _ := json.Marshal("\b\f")
if (string(data) == "\"\\b\\f\"") {
// Go version 1.22+ encodes "\b" and "\f" correctly.
testJSONString(t, "\b\f") testJSONString(t, "\b\f")
rng := rand.New(rand.NewSource(time.Now().UnixNano())) rng := rand.New(rand.NewSource(time.Now().UnixNano()))
start := time.Now() start := time.Now()
@ -2588,6 +2591,7 @@ func TestJSONString(t *testing.T) {
} }
testJSONString(t, string(buf[:])) testJSONString(t, string(buf[:]))
} }
}
} }
func TestIndexAtSymbol(t *testing.T) { func TestIndexAtSymbol(t *testing.T) {