@twin.org/data-json-path 0.0.3-next.16 → 0.0.3-next.17
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 +1 -1
- package/docs/changelog.md +8 -1
- package/docs/examples.md +60 -1
- package/package.json +2 -2
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,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [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)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **data-json-path:** Synchronize repo versions
|
|
2
9
|
|
|
3
10
|
## [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
11
|
|
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
|
+
```
|
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.17",
|
|
4
|
+
"description": "A consistent JSONPath query abstraction.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/data.git",
|