Commit Graph

308 Commits

Author SHA1 Message Date
tidwall c2bc5a409a dark mode logo 2024-06-02 18:12:06 -07:00
Josh Baker 2ba56cc086
Merge pull request #354 from rustfix/master
chore: fix some typos in comments
2024-04-22 19:12:58 -07:00
rustfix 5d0d40c89f chore: fix some typos in comments
Signed-off-by: rustfix <771054535@qq.com>
2024-04-15 11:43:24 +08:00
tidwall bbf40bb0e4 Fix backspace and form-feed for Go 1.22 2024-02-14 20:51:40 -07:00
Josh Baker 711c6fe9ec
Merge pull request #348 from V02460/json_string
Encode \b and \f in JSON string as themselves
2024-02-14 19:46:13 -07:00
Kai A. Hiller 0f87896dc3 Test \b and \f JSON encoding explicitly 2024-02-14 21:15:12 +01:00
Kai A. Hiller b622071bec Encode \b and \f in JSON string as themselves 2024-02-14 21:14:05 +01:00
tidwall 6ee9f877d6 Added Escape function
This commit adds the Escape function for escaping a path
component, making it possible to directly querying keys that have
special characters like dots.

```
json := `{
  "user":{
      "first.name": "Janet",
      "last.name": "Prichard"
    }
}`
user := gjson.Get(json, "user")
println(user.Get(gjson.Escape("first.name")).String())
println(user.Get(gjson.Escape("last.name")).String())
// Output:
// Janet
// Prichard
```

See #333
2023-09-22 10:13:56 -07:00
tidwall be1bb7d64a Update README.md 2023-09-22 09:54:14 -07:00
tidwall 1ff915dd81 Mention the dig modifier 2023-08-09 15:09:36 -07:00
tidwall e8e87f2a00 Add @dig modifier for recursive descent searches
This commit adds the "@dig" modifier, which allows for searching
for values in deep or arbitrarily nested json documents

For example, using the following json:

```
{ "something": {
    "anything": {
      "abcdefg": {
          "finally": {
            "important": {
                "secret": "password"
            }
        }
      }
    }
  }
}
```

```
@dig:secret  ->  ["password"]
```

See #130
2023-08-09 14:54:46 -07:00
tidwall 8d2c36ffa4 Added new tilde types and fixed ~false
This commit fixes an issue with ~false where the it's value was
simply the opposite of ~true. Now ~false explicitly checks for
false-ish values.

Also added ~null and ~* for testing null-ish and non-existent
values.

see #327
2023-07-27 06:23:49 -07:00
tidwall e14b8d3708 Add test 2022-11-21 18:54:56 -07:00
Josh Baker f37cc44a28
Merge pull request #301 from svher/master
fix object path parse error
2022-11-21 18:52:24 -07:00
GuitarBoy 1ed0d856e3
bug fix 2022-11-21 14:37:46 +08:00
Josh Baker 0fc85398c8
Merge pull request #299 from bashery/master
doc: int64 --> uint64
2022-11-13 21:15:28 -07:00
bashery 25df3e611a uint64 2022-10-31 17:56:38 +03:00
Josh Baker 8bf80a300b
Merge pull request #291 from janisz/master
Handle modifiers with options
2022-08-16 06:44:06 -07:00
Tomasz Janiszewski 9e848707d6
Handle modifiers with options 2022-08-09 15:41:28 +02:00
tidwall 475b4036c3 Allow for Index > 0 on path compontent that are not modifiers.
This commit fixes an issue where non-modifier path components
such as '@hello' return 0 for the Result.Index value.
2022-08-04 18:06:36 -07:00
Josh Baker 980f12c60e
Merge pull request #282 from L2ncE/master
Fix a syntax error in a code comment
2022-06-21 13:49:08 -07:00
L2ncE 72953c7472 Fix a syntax error in a code comment 2022-06-15 16:59:08 +08:00
Josh Baker f37ee93f13
Update README.md 2022-06-13 06:38:27 -07:00
Josh Baker e20a0bfa61
Delete FUNDING.yml 2022-05-14 10:33:26 -07:00
tidwall c3bb2c39ba Remove encoding/json dependency
The only purpose of using the built-in Go was to encode json
strings that had unicode or needed to escaped.

This commit adds the new function `AppendJSONString` which allows
for appending strings as their json representation to a byte
slice.

It's about 2x faster than using json.Marshal.
2022-04-19 15:14:33 -07:00
tidwall 56c0a0aa5b Update comment 2022-03-22 09:30:19 -07:00
Josh Baker 7a94820afd
Update SYNTAX.md 2022-02-02 04:59:12 -07:00
Josh Baker 1abd525f6d
Update README.md 2022-02-02 04:58:31 -07:00
Josh Baker fce6fec098
Update README.md 2022-02-02 04:57:03 -07:00
tidwall 05e9ee1423 Update docs 2022-02-02 04:52:59 -07:00
tidwall 82f549e6ee Added IsBool
See #264
2022-02-02 04:49:11 -07:00
tidwall e4fc67c92a Added group modifier
The new "@group" modifier allows for grouping arrays of objects.

For example, using the "@group" modifier on the following json...

  {"id":["123","456","789"],"val":[2,1]}

will results in...

  [{"id":"123","val":2},{"id":"456","val":1},{"id":"789"}]
2022-02-02 04:43:04 -07:00
Josh Baker f47e17d70a
Update README.md
Added an additional link to the SYNTAX doc. 

#261
2022-01-13 18:19:20 -07:00
tidwall 38071ea7f2 Add tostr and fromstr modifiers
For wrapping and unwrapping json strings
2022-01-13 09:15:39 -07:00
Josh Baker ba95ef80b5
Update SYNTAX.md 2021-12-10 09:23:12 -07:00
Josh Baker 65bbebbdf7
Fixed typo 2021-12-08 09:42:11 -07:00
tidwall db0033701c Set array index as key for ForEach
See #248
2021-11-30 17:20:07 -07:00
Josh Baker bd76212030
Add syntax badge 2021-11-30 10:22:50 -07:00
tidwall 9eae1fa87b Added JSON Literals 2021-11-30 10:18:36 -07:00
tidwall d3a134957c Fix modifier bug in multipath selector
Closes #253
2021-11-25 13:57:06 -07:00
tidwall 6b6af2ad5e Added new static value character
You can use the '!' character to define static json as a path
component.

For example,

  {name.last,"foo":!"bar"} => {name.last,"foo":"bar"}

see #249
2021-11-10 09:18:18 -07:00
tidwall 2c9fd2476a Added Path and Paths for getting the original path of a Result
This commit adds a two new functions of the Result type:

- Result.Path:  Returns the original path of a `Result` that was
                returned from a simple `Get` operation.
- Result.Paths: Returns the original paths of a `Result` that was
                returned from a `Get` operation with a query.

See issue #206 for more details
2021-10-29 17:30:57 -07:00
tidwall 7cadbb5756 Ensure Parse handles NaN/Inf and returns correct Index 2021-10-28 09:09:00 -07:00
tidwall 0b52f9a361 Fix empty string operator not matching
fixes #246
2021-10-25 07:11:04 -07:00
tidwall 8ac7a764ca Update README.md 2021-10-22 05:10:12 -07:00
tidwall 5784e4879e cleanup test 2021-10-22 04:05:41 -07:00
tidwall 0cbc0f402f Accept NaN/Inf
This commit allows for NaN and Inf numbers.

see #242
2021-10-22 04:00:22 -07:00
tidwall 35fa0d71c8 Added @keys and @values modifiers
The "@keys" and "@values" modifiers converts an object into an
array of its keys or values respectively.

Take this json for example:

{"first":"Tom","last":"Smith"}

@keys   -> ["first","last"]
@values -> ["Tom","Smith"]

This feature was requested in #161.
2021-10-20 16:31:29 -07:00
tidwall 4fe1916c56 The Array method should return back one item for JSON objects.
This commit fixes an issue where the Array method was not
returning single value arrays when the reciever Result was a
JSON Object.

fixes #240
2021-10-12 10:52:30 -07:00
tidwall 77a57fda87 Limit the complexity of "like" queries that match on a pattern.
This commit adds the uses the MatchLimit function, which it the
same as Match but will limit the complexity of the input pattern.
This is to avoid long running matches, specifically to avoid ReDos
attacks from arbritary inputs.
2021-10-08 07:42:49 -07:00