@twin.org/data-json-path 0.0.3-next.16 → 0.0.3-next.18
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.
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TWIN Data JSONPath
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides a consistent abstraction for JSONPath queries, helping teams read and filter complex JSON structures through one stable interface. It builds on [JSONPath](https://goessner.net/articles/JsonPath/) concepts and the `json-p3` implementation to support reliable document querying across the repository.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.18](https://github.com/twinfoundation/data/compare/data-json-path-v0.0.3-next.17...data-json-path-v0.0.3-next.18) (2026-03-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **data-json-path:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
## [0.0.3-next.17](https://github.com/twinfoundation/data/compare/data-json-path-v0.0.3-next.16...data-json-path-v0.0.3-next.17) (2026-03-12)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Miscellaneous Chores
|
|
14
|
+
|
|
15
|
+
* **data-json-path:** Synchronize repo versions
|
|
2
16
|
|
|
3
17
|
## [0.0.3-next.16](https://github.com/twinfoundation/data/compare/data-json-path-v0.0.3-next.15...data-json-path-v0.0.3-next.16) (2026-03-06)
|
|
4
18
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Data Json Path Examples
|
|
2
|
+
|
|
3
|
+
These snippets cover common query and update workflows for nested JSON structures.
|
|
4
|
+
|
|
5
|
+
## JsonPathHelper
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { JsonPathHelper } from '@twin.org/data-json-path';
|
|
9
|
+
|
|
10
|
+
const sample = {
|
|
11
|
+
store: {
|
|
12
|
+
book: [
|
|
13
|
+
{ title: 'The Left Hand of Darkness', price: 8.99 },
|
|
14
|
+
{ title: 'A Wizard of Earthsea', price: 6.5 }
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const queryResults = JsonPathHelper.query('$.store.book[*].title', sample);
|
|
20
|
+
console.log('Query result count:', queryResults.length);
|
|
21
|
+
|
|
22
|
+
console.log('Path exists:', JsonPathHelper.exists('$.store.book[0].price', sample));
|
|
23
|
+
console.log('Single value:', JsonPathHelper.extractSingle('$.store.book[0].title', sample));
|
|
24
|
+
console.log('All prices:', JsonPathHelper.extractAll('$.store.book[*].price', sample));
|
|
25
|
+
console.log('Path is valid:', JsonPathHelper.validate('$.store.book[*].title'));
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { JsonPathHelper } from '@twin.org/data-json-path';
|
|
30
|
+
|
|
31
|
+
const profile = {
|
|
32
|
+
user: {
|
|
33
|
+
name: 'Ada',
|
|
34
|
+
contact: {
|
|
35
|
+
email: 'ada@example.org'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const emailNode = JsonPathHelper.query('$.user.contact.email', profile)[0];
|
|
41
|
+
JsonPathHelper.setAtLocation(profile, emailNode.location, 'ada.lovelace@example.org');
|
|
42
|
+
|
|
43
|
+
console.log('Updated email:', profile.user.contact.email);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { JsonPathHelper } from '@twin.org/data-json-path';
|
|
48
|
+
|
|
49
|
+
const payload = {
|
|
50
|
+
user: {
|
|
51
|
+
id: 'u-100',
|
|
52
|
+
sessionToken: 'token-abc'
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const tokenNode = JsonPathHelper.query('$.user.sessionToken', payload)[0];
|
|
57
|
+
JsonPathHelper.deleteAtLocation(payload, tokenNode.location);
|
|
58
|
+
|
|
59
|
+
console.log('Token removed:', !('sessionToken' in payload.user));
|
|
60
|
+
```
|
|
@@ -15,7 +15,7 @@ Provides abstraction over the json-p3 library.
|
|
|
15
15
|
|
|
16
16
|
## Properties
|
|
17
17
|
|
|
18
|
-
### CLASS\_NAME
|
|
18
|
+
### CLASS\_NAME {#class_name}
|
|
19
19
|
|
|
20
20
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
21
21
|
|
|
@@ -23,7 +23,7 @@ The name of the class name of the JsonPathHelper class.
|
|
|
23
23
|
|
|
24
24
|
## Methods
|
|
25
25
|
|
|
26
|
-
### query()
|
|
26
|
+
### query() {#query}
|
|
27
27
|
|
|
28
28
|
> `static` **query**(`path`, `data`): [`IJsonPathResult`](../interfaces/IJsonPathResult.md)[]
|
|
29
29
|
|
|
@@ -55,7 +55,7 @@ GeneralError if the path is invalid or data cannot be queried.
|
|
|
55
55
|
|
|
56
56
|
***
|
|
57
57
|
|
|
58
|
-
### exists()
|
|
58
|
+
### exists() {#exists}
|
|
59
59
|
|
|
60
60
|
> `static` **exists**(`path`, `data`): `boolean`
|
|
61
61
|
|
|
@@ -83,7 +83,7 @@ True if the path exists and returns at least one result.
|
|
|
83
83
|
|
|
84
84
|
***
|
|
85
85
|
|
|
86
|
-
### extractSingle()
|
|
86
|
+
### extractSingle() {#extractsingle}
|
|
87
87
|
|
|
88
88
|
> `static` **extractSingle**(`path`, `data`): `unknown`
|
|
89
89
|
|
|
@@ -115,7 +115,7 @@ GeneralError if the path is invalid or data cannot be queried.
|
|
|
115
115
|
|
|
116
116
|
***
|
|
117
117
|
|
|
118
|
-
### extractAll()
|
|
118
|
+
### extractAll() {#extractall}
|
|
119
119
|
|
|
120
120
|
> `static` **extractAll**(`path`, `data`): `unknown`[]
|
|
121
121
|
|
|
@@ -147,7 +147,7 @@ GeneralError if the path is invalid or data cannot be queried.
|
|
|
147
147
|
|
|
148
148
|
***
|
|
149
149
|
|
|
150
|
-
### validate()
|
|
150
|
+
### validate() {#validate}
|
|
151
151
|
|
|
152
152
|
> `static` **validate**(`path`): `boolean`
|
|
153
153
|
|
|
@@ -173,7 +173,7 @@ GeneralError if the path is invalid or data cannot be queried.
|
|
|
173
173
|
|
|
174
174
|
***
|
|
175
175
|
|
|
176
|
-
### setAtLocation()
|
|
176
|
+
### setAtLocation() {#setatlocation}
|
|
177
177
|
|
|
178
178
|
> `static` **setAtLocation**(`root`, `location`, `value`): `void`
|
|
179
179
|
|
|
@@ -205,7 +205,7 @@ The value to set.
|
|
|
205
205
|
|
|
206
206
|
***
|
|
207
207
|
|
|
208
|
-
### deleteAtLocation()
|
|
208
|
+
### deleteAtLocation() {#deleteatlocation}
|
|
209
209
|
|
|
210
210
|
> `static` **deleteAtLocation**(`root`, `location`): `void`
|
|
211
211
|
|
|
@@ -4,7 +4,7 @@ Result from a JSONPath query operation.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### value
|
|
7
|
+
### value {#value}
|
|
8
8
|
|
|
9
9
|
> **value**: `unknown`
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ The value at the matched path.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### location
|
|
15
|
+
### location {#location}
|
|
16
16
|
|
|
17
17
|
> **location**: [`IJsonPathLocation`](../type-aliases/IJsonPathLocation.md)
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ The location path to the value.
|
|
|
20
20
|
|
|
21
21
|
***
|
|
22
22
|
|
|
23
|
-
### path
|
|
23
|
+
### path {#path}
|
|
24
24
|
|
|
25
25
|
> **path**: `string`
|
|
26
26
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/data-json-path",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.18",
|
|
4
|
+
"description": "A consistent JSONPath query abstraction.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/data.git",
|