philiprehberger-json_path 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +5 -0
- data/lib/philiprehberger/json_path/version.rb +1 -1
- data/lib/philiprehberger/json_path.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d1f6e3df479eeb12b69af816742069bd38c31953c3b1611add83bc3aac4434a
|
|
4
|
+
data.tar.gz: 69b8a9a12b7a95fcf12ac173c6559d9e002a9d8d085c05b28716eb9948262fe5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c603bf6cd3c2a58f248b1ca535ebcd63d28f3d1cdc269ff73f7e2889f161316c0a1c3a710c7e250c5529d090458fc42ffeac1cb2a43020fb81d037b500548a04
|
|
7
|
+
data.tar.gz: 12a21c296a86fe78d87ffd71ad9bba9b81200d60c8ffb1f3959e77f56f7312d31fda4d04fc00e3baa37103dee548237d0827810d8abe672b148b696d86f9c9e4
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-19
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `JsonPath.last(data, path)` — last matching value; symmetric with existing `.first`; returns `nil` on no match
|
|
14
|
+
|
|
10
15
|
## [0.3.0] - 2026-04-17
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -48,6 +48,10 @@ Philiprehberger::JsonPath.values(data, '$.store.books[*].title')
|
|
|
48
48
|
Philiprehberger::JsonPath.first(data, '$.store.books[0].title')
|
|
49
49
|
# => "Ruby"
|
|
50
50
|
|
|
51
|
+
items = { "items" => [{ "id" => 1 }, { "id" => 2 }, { "id" => 3 }] }
|
|
52
|
+
Philiprehberger::JsonPath.first(items, "$.items[*].id") # => 1
|
|
53
|
+
Philiprehberger::JsonPath.last(items, "$.items[*].id") # => 3
|
|
54
|
+
|
|
51
55
|
Philiprehberger::JsonPath.count(data, '$.store.books[*]')
|
|
52
56
|
# => 3
|
|
53
57
|
|
|
@@ -149,6 +153,7 @@ Philiprehberger::JsonPath.query(data, '$.groups[?(@.members.length > 0)].name')
|
|
|
149
153
|
| `JsonPath.query(data, path)` | Return all matches as an array |
|
|
150
154
|
| `JsonPath.values(data, path)` | Alias for `query` |
|
|
151
155
|
| `JsonPath.first(data, path)` | Return the first match or nil |
|
|
156
|
+
| `JsonPath.last(data, path)` | Return the last match or nil |
|
|
152
157
|
| `JsonPath.count(data, path)` | Return the number of matches |
|
|
153
158
|
| `JsonPath.exists?(data, path)` | Check if any match exists |
|
|
154
159
|
| `JsonPath.paths(data, path)` | Return canonical JSONPath strings for each match |
|
|
@@ -34,6 +34,15 @@ module Philiprehberger
|
|
|
34
34
|
query(data, path).first
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
# Query data and return the last match
|
|
38
|
+
#
|
|
39
|
+
# @param data [Hash, Array] the data structure to query
|
|
40
|
+
# @param path [String] JSONPath expression
|
|
41
|
+
# @return [Object, nil] the last matching value or nil
|
|
42
|
+
def self.last(data, path)
|
|
43
|
+
query(data, path).last
|
|
44
|
+
end
|
|
45
|
+
|
|
37
46
|
# Return the number of matches for a JSONPath expression
|
|
38
47
|
#
|
|
39
48
|
# @param data [Hash, Array] the data structure to query
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-json_path
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- philiprehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Evaluate JSONPath expressions against Ruby hashes and arrays. Supports
|
|
14
14
|
dot notation, array indexing, wildcards, slices, filter expressions, recursive descent,
|