@twin.org/data-json-path 0.0.3-next.2 → 0.0.3-next.21

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
- JSONPath abstraction layer for TWIN platform.
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/dist/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright 2025 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  export * from "./jsonPathHelper.js";
4
+ export * from "./models/IJsonPathLocation.js";
4
5
  export * from "./models/IJsonPathResult.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./jsonPathHelper.js\";\nexport * from \"./models/IJsonPathResult.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./jsonPathHelper.js\";\nexport * from \"./models/IJsonPathLocation.js\";\nexport * from \"./models/IJsonPathResult.js\";\n"]}
@@ -114,5 +114,105 @@ export class JsonPathHelper {
114
114
  }, BaseError.fromError(error));
115
115
  }
116
116
  }
117
+ /**
118
+ * Set a value on the target object using a JSONPath location.
119
+ * @param root The target root object.
120
+ * @param location The JSONPath location tokens.
121
+ * @param value The value to set.
122
+ */
123
+ static setAtLocation(root, location, value) {
124
+ if (!Is.arrayValue(location) || location.length === 0) {
125
+ return;
126
+ }
127
+ let current = root;
128
+ for (let i = 0; i < location.length - 1; i++) {
129
+ const token = location[i];
130
+ const nextToken = location[i + 1];
131
+ if (!Is.array(current) && !Is.object(current)) {
132
+ return;
133
+ }
134
+ if (Is.number(token)) {
135
+ if (!Is.array(current)) {
136
+ return;
137
+ }
138
+ const existing = current[token];
139
+ if (!Is.array(existing) && !Is.object(existing)) {
140
+ current[token] = Is.number(nextToken) ? [] : {};
141
+ }
142
+ current = current[token];
143
+ }
144
+ else {
145
+ if (!Is.object(current)) {
146
+ return;
147
+ }
148
+ const existing = current[token];
149
+ if (!Is.array(existing) && !Is.object(existing)) {
150
+ current[token] = Is.number(nextToken) ? [] : {};
151
+ }
152
+ current = current[token];
153
+ }
154
+ }
155
+ const lastToken = location[location.length - 1];
156
+ if (!Is.array(current) && !Is.object(current)) {
157
+ return;
158
+ }
159
+ if (Is.number(lastToken)) {
160
+ if (!Is.array(current)) {
161
+ return;
162
+ }
163
+ current[lastToken] = value;
164
+ }
165
+ else {
166
+ if (!Is.object(current)) {
167
+ return;
168
+ }
169
+ current[lastToken] = value;
170
+ }
171
+ }
172
+ /**
173
+ * Delete a value on the target object using a JSONPath location.
174
+ * @param root The target root object.
175
+ * @param location The JSONPath location tokens.
176
+ */
177
+ static deleteAtLocation(root, location) {
178
+ if (!Is.arrayValue(location) || location.length === 0) {
179
+ return;
180
+ }
181
+ let current = root;
182
+ for (let i = 0; i < location.length - 1; i++) {
183
+ const token = location[i];
184
+ if (!Is.array(current) && !Is.object(current)) {
185
+ return;
186
+ }
187
+ if (Is.number(token)) {
188
+ if (!Is.array(current)) {
189
+ return;
190
+ }
191
+ current = current[token];
192
+ }
193
+ else {
194
+ if (!Is.object(current)) {
195
+ return;
196
+ }
197
+ current = current[token];
198
+ }
199
+ }
200
+ if (!Is.array(current) && !Is.object(current)) {
201
+ return;
202
+ }
203
+ const lastToken = location[location.length - 1];
204
+ if (Is.number(lastToken)) {
205
+ if (!Is.array(current)) {
206
+ return;
207
+ }
208
+ current[lastToken] = undefined;
209
+ }
210
+ else {
211
+ if (!Is.object(current)) {
212
+ return;
213
+ }
214
+ delete current[lastToken];
215
+ }
216
+ }
117
217
  }
118
218
  //# sourceMappingURL=jsonPathHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsonPathHelper.js","sourceRoot":"","sources":["../../src/jsonPathHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAC;AAGnD;;;GAGG;AACH,MAAM,OAAO,cAAc;IAC1B;;OAEG;IACI,MAAM,CAAU,UAAU,oBAAoC;IAErE;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,IAAY,EAAE,IAAa;QAC9C,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAElE,IAAI,CAAC;YACJ,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAiB,CAAC,CAAC;YACxD,uDAAuD;YACvD,MAAM,WAAW,GAAsB,EAAE,CAAC;YAC1C,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC5B,WAAW,CAAC,IAAI,CAAC;oBAChB,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;iBACzC,CAAC,CAAC;YACJ,CA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AO,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAiB,CAAC,CAAC;YACxD,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CACrB,cAAc,CAAC,UAAU,EACzB,kBAAkB,EAClB;gBACC,IAAI;aACJ,EACD,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAC1B,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,QAAQ,CAAC,IAAY;QAClC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACJ,yCAAyC;YACzC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACzB,OAAO,IAAI,CAAC;QACb,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CACrB,cAAc,CAAC,UAAU,EACzB,gBAAgB,EAChB;gBACC,IAAI;aACJ,EACD,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAC1B,CAAC;QACH,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, GeneralError, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { jsonpath, type JSONValue } from \"json-p3\";\nimport type { IJsonPathResult } from \"./models/IJsonPathResult.js\";\n\n/**\n * Helper class for JSONPath operations.\n * Provides abstraction over the json-p3 library.\n */\nexport class JsonPathHelper {\n\t/**\n\t * The name of the class name of the JsonPathHelper class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JsonPathHelper>();\n\n\t/**\n\t * Execute a JSONPath query and return results with values and locations.\n\t * @param path The JSONPath query string (e.g., \"$.store.book[*].title\").\n\t * @param data The data to query.\n\t * @returns Array of results containing values and their locations.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static query(path: string, data: unknown): IJsonPathResult[] {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst results = jsonpath.query(path, data as JSONValue);\n\t\t\t// Convert JSONPathNodeList to array of IJsonPathResult\n\t\t\tconst resultArray: IJsonPathResult[] = [];\n\t\t\tfor (const node of results) {\n\t\t\t\tresultArray.push({\n\t\t\t\t\tvalue: node.value,\n\t\t\t\t\tlocation: node.location,\n\t\t\t\t\tpath: node.getPath({ form: \"canonical\" })\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn resultArray;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"query\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Check if a JSONPath exists in the data.\n\t * @param path The JSONPath query string.\n\t * @param data The data to check.\n\t * @returns True if the path exists and returns at least one result.\n\t */\n\tpublic static exists(path: string, data: unknown): boolean {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst results = jsonpath.query(path, data as JSONValue);\n\t\t\treturn !results.empty();\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Extract the first value from a JSONPath query.\n\t * @param path The JSONPath query string.\n\t * @param data The data to query.\n\t * @returns The first matched value, or undefined if no matches.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static extractSingle(path: string, data: unknown): unknown {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst node = jsonpath.match(path, data as JSONValue);\n\t\t\treturn node?.value;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"extractSingleFailed\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Extract all values from a JSONPath query.\n\t * @param path The JSONPath query string.\n\t * @param data The data to query.\n\t * @returns Array of all matched values.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static extractAll(path: string, data: unknown): unknown[] {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst results = jsonpath.query(path, data as JSONValue);\n\t\t\treturn results.values();\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"extractAllFailed\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validate if a JSONPath query is valid.\n\t * @param path The JSONPath query string to validate.\n\t * @returns True if the syntax is valid.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static validate(path: string): boolean {\n\t\tif (!Is.stringValue(path)) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\t// Query with empty object to test syntax\n\t\t\tjsonpath.query(path, {});\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"validateFailed\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"jsonPathHelper.js","sourceRoot":"","sources":["../../src/jsonPathHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,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C;QAChD,IAAI,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBACxB,OAAO;YACR,CAAC;YACD,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzB,OAAO;YACR,CAAC;YACD,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, GeneralError, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { jsonpath, type JSONValue } from \"json-p3\";\nimport type { IJsonPathLocation } from \"./models/IJsonPathLocation.js\";\nimport type { IJsonPathResult } from \"./models/IJsonPathResult.js\";\n\n/**\n * Helper class for JSONPath operations.\n * Provides abstraction over the json-p3 library.\n */\nexport class JsonPathHelper {\n\t/**\n\t * The name of the class name of the JsonPathHelper class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JsonPathHelper>();\n\n\t/**\n\t * Execute a JSONPath query and return results with values and locations.\n\t * @param path The JSONPath query string (e.g., \"$.store.book[*].title\").\n\t * @param data The data to query.\n\t * @returns Array of results containing values and their locations.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static query(path: string, data: unknown): IJsonPathResult[] {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst results = jsonpath.query(path, data as JSONValue);\n\t\t\t// Convert JSONPathNodeList to array of IJsonPathResult\n\t\t\tconst resultArray: IJsonPathResult[] = [];\n\t\t\tfor (const node of results) {\n\t\t\t\tresultArray.push({\n\t\t\t\t\tvalue: node.value,\n\t\t\t\t\tlocation: node.location,\n\t\t\t\t\tpath: node.getPath({ form: \"canonical\" })\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn resultArray;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"query\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Check if a JSONPath exists in the data.\n\t * @param path The JSONPath query string.\n\t * @param data The data to check.\n\t * @returns True if the path exists and returns at least one result.\n\t */\n\tpublic static exists(path: string, data: unknown): boolean {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst results = jsonpath.query(path, data as JSONValue);\n\t\t\treturn !results.empty();\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Extract the first value from a JSONPath query.\n\t * @param path The JSONPath query string.\n\t * @param data The data to query.\n\t * @returns The first matched value, or undefined if no matches.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static extractSingle(path: string, data: unknown): unknown {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst node = jsonpath.match(path, data as JSONValue);\n\t\t\treturn node?.value;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"extractSingleFailed\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Extract all values from a JSONPath query.\n\t * @param path The JSONPath query string.\n\t * @param data The data to query.\n\t * @returns Array of all matched values.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static extractAll(path: string, data: unknown): unknown[] {\n\t\tGuards.stringValue(JsonPathHelper.CLASS_NAME, nameof(path), path);\n\n\t\ttry {\n\t\t\tconst results = jsonpath.query(path, data as JSONValue);\n\t\t\treturn results.values();\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"extractAllFailed\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validate if a JSONPath query is valid.\n\t * @param path The JSONPath query string to validate.\n\t * @returns True if the syntax is valid.\n\t * @throws GeneralError if the path is invalid or data cannot be queried.\n\t */\n\tpublic static validate(path: string): boolean {\n\t\tif (!Is.stringValue(path)) {\n\t\t\treturn false;\n\t\t}\n\n\t\ttry {\n\t\t\t// Query with empty object to test syntax\n\t\t\tjsonpath.query(path, {});\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tJsonPathHelper.CLASS_NAME,\n\t\t\t\t\"validateFailed\",\n\t\t\t\t{\n\t\t\t\t\tpath\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Set a value on the target object using a JSONPath location.\n\t * @param root The target root object.\n\t * @param location The JSONPath location tokens.\n\t * @param value The value to set.\n\t */\n\tpublic static setAtLocation(root: unknown, location: IJsonPathLocation, value: unknown): void {\n\t\tif (!Is.arrayValue(location) || location.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet current: unknown = root;\n\t\tfor (let i = 0; i < location.length - 1; i++) {\n\t\t\tconst token = location[i];\n\t\t\tconst nextToken = location[i + 1];\n\n\t\t\tif (!Is.array(current) && !Is.object(current)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (Is.number(token)) {\n\t\t\t\tif (!Is.array(current)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst existing = current[token];\n\t\t\t\tif (!Is.array(existing) && !Is.object(existing)) {\n\t\t\t\t\tcurrent[token] = Is.number(nextToken) ? [] : {};\n\t\t\t\t}\n\t\t\t\tcurrent = current[token];\n\t\t\t} else {\n\t\t\t\tif (!Is.object(current)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst existing = current[token];\n\t\t\t\tif (!Is.array(existing) && !Is.object(existing)) {\n\t\t\t\t\tcurrent[token] = Is.number(nextToken) ? [] : {};\n\t\t\t\t}\n\t\t\t\tcurrent = current[token];\n\t\t\t}\n\t\t}\n\n\t\tconst lastToken = location[location.length - 1];\n\t\tif (!Is.array(current) && !Is.object(current)) {\n\t\t\treturn;\n\t\t}\n\t\tif (Is.number(lastToken)) {\n\t\t\tif (!Is.array(current)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcurrent[lastToken] = value;\n\t\t} else {\n\t\t\tif (!Is.object(current)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcurrent[lastToken] = value;\n\t\t}\n\t}\n\n\t/**\n\t * Delete a value on the target object using a JSONPath location.\n\t * @param root The target root object.\n\t * @param location The JSONPath location tokens.\n\t */\n\tpublic static deleteAtLocation(root: unknown, location: IJsonPathLocation): void {\n\t\tif (!Is.arrayValue(location) || location.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet current: unknown = root;\n\t\tfor (let i = 0; i < location.length - 1; i++) {\n\t\t\tconst token = location[i];\n\t\t\tif (!Is.array(current) && !Is.object(current)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (Is.number(token)) {\n\t\t\t\tif (!Is.array(current)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcurrent = current[token];\n\t\t\t} else {\n\t\t\t\tif (!Is.object(current)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcurrent = current[token];\n\t\t\t}\n\t\t}\n\n\t\tif (!Is.array(current) && !Is.object(current)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lastToken = location[location.length - 1];\n\t\tif (Is.number(lastToken)) {\n\t\t\tif (!Is.array(current)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcurrent[lastToken] = undefined;\n\t\t} else {\n\t\t\tif (!Is.object(current)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdelete current[lastToken];\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2025 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IJsonPathLocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IJsonPathLocation.js","sourceRoot":"","sources":["../../../src/models/IJsonPathLocation.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Result paths from a JSONPath query operation.\n */\nexport type IJsonPathLocation = (string | number)[];\n"]}
@@ -1,4 +1,2 @@
1
- // Copyright 2025 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
1
  export {};
4
2
  //# sourceMappingURL=IJsonPathResult.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IJsonPathResult.js","sourceRoot":"","sources":["../../../src/models/IJsonPathResult.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Result from a JSONPath query operation.\n */\nexport interface IJsonPathResult {\n\t/**\n\t * The value at the matched path.\n\t */\n\tvalue: unknown;\n\n\t/**\n\t * The location path to the value.\n\t */\n\tlocation: (string | number)[];\n\n\t/**\n\t * The location path as a string for debugging.\n\t */\n\tpath: string;\n}\n"]}
1
+ {"version":3,"file":"IJsonPathResult.js","sourceRoot":"","sources":["../../../src/models/IJsonPathResult.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonPathLocation } from \"./IJsonPathLocation.js\";\n\n/**\n * Result from a JSONPath query operation.\n */\nexport interface IJsonPathResult {\n\t/**\n\t * The value at the matched path.\n\t */\n\tvalue: unknown;\n\n\t/**\n\t * The location path to the value.\n\t */\n\tlocation: IJsonPathLocation;\n\n\t/**\n\t * The location path as a string for debugging.\n\t */\n\tpath: string;\n}\n"]}
@@ -1,2 +1,3 @@
1
1
  export * from "./jsonPathHelper.js";
2
+ export * from "./models/IJsonPathLocation.js";
2
3
  export * from "./models/IJsonPathResult.js";
@@ -1,3 +1,4 @@
1
+ import type { IJsonPathLocation } from "./models/IJsonPathLocation.js";
1
2
  import type { IJsonPathResult } from "./models/IJsonPathResult.js";
2
3
  /**
3
4
  * Helper class for JSONPath operations.
@@ -46,4 +47,17 @@ export declare class JsonPathHelper {
46
47
  * @throws GeneralError if the path is invalid or data cannot be queried.
47
48
  */
48
49
  static validate(path: string): boolean;
50
+ /**
51
+ * Set a value on the target object using a JSONPath location.
52
+ * @param root The target root object.
53
+ * @param location The JSONPath location tokens.
54
+ * @param value The value to set.
55
+ */
56
+ static setAtLocation(root: unknown, location: IJsonPathLocation, value: unknown): void;
57
+ /**
58
+ * Delete a value on the target object using a JSONPath location.
59
+ * @param root The target root object.
60
+ * @param location The JSONPath location tokens.
61
+ */
62
+ static deleteAtLocation(root: unknown, location: IJsonPathLocation): void;
49
63
  }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Result paths from a JSONPath query operation.
3
+ */
4
+ export type IJsonPathLocation = (string | number)[];
@@ -1,3 +1,4 @@
1
+ import type { IJsonPathLocation } from "./IJsonPathLocation.js";
1
2
  /**
2
3
  * Result from a JSONPath query operation.
3
4
  */
@@ -9,7 +10,7 @@ export interface IJsonPathResult {
9
10
  /**
10
11
  * The location path to the value.
11
12
  */
12
- location: (string | number)[];
13
+ location: IJsonPathLocation;
13
14
  /**
14
15
  * The location path as a string for debugging.
15
16
  */
package/docs/changelog.md CHANGED
@@ -1,21 +1,154 @@
1
- # @twin.org/data-json-path - Changelog
1
+ # Changelog
2
2
 
3
- ## [0.0.3-next.2](https://github.com/twinfoundation/data/compare/data-json-path-v0.0.3-next.1...data-json-path-v0.0.3-next.2) (2025-11-24)
3
+ ## [0.0.3-next.21](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.20...data-json-path-v0.0.3-next.21) (2026-05-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * typescript 6 update ([44cbfe8](https://github.com/iotaledger/twin-data/commit/44cbfe87256282b9928134b2bbed1d3c6ee15acb))
9
+
10
+ ## [0.0.3-next.20](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.19...data-json-path-v0.0.3-next.20) (2026-03-24)
11
+
12
+
13
+ ### Miscellaneous Chores
14
+
15
+ * **data-json-path:** Synchronize repo versions
16
+
17
+ ## [0.0.3-next.19](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.18...data-json-path-v0.0.3-next.19) (2026-03-20)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **data-json-path:** Synchronize repo versions
23
+
24
+ ## [0.0.3-next.18](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.17...data-json-path-v0.0.3-next.18) (2026-03-16)
25
+
26
+
27
+ ### Miscellaneous Chores
28
+
29
+ * **data-json-path:** Synchronize repo versions
30
+
31
+ ## [0.0.3-next.17](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.16...data-json-path-v0.0.3-next.17) (2026-03-12)
32
+
33
+
34
+ ### Miscellaneous Chores
35
+
36
+ * **data-json-path:** Synchronize repo versions
37
+
38
+ ## [0.0.3-next.16](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.15...data-json-path-v0.0.3-next.16) (2026-03-06)
39
+
40
+
41
+ ### Miscellaneous Chores
42
+
43
+ * **data-json-path:** Synchronize repo versions
44
+
45
+ ## [0.0.3-next.15](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.14...data-json-path-v0.0.3-next.15) (2026-02-27)
46
+
47
+
48
+ ### Miscellaneous Chores
49
+
50
+ * **data-json-path:** Synchronize repo versions
51
+
52
+ ## [0.0.3-next.14](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.13...data-json-path-v0.0.3-next.14) (2026-02-25)
53
+
54
+
55
+ ### Miscellaneous Chores
56
+
57
+ * **data-json-path:** Synchronize repo versions
58
+
59
+ ## [0.0.3-next.13](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.12...data-json-path-v0.0.3-next.13) (2026-02-25)
60
+
61
+
62
+ ### Miscellaneous Chores
63
+
64
+ * **data-json-path:** Synchronize repo versions
65
+
66
+ ## [0.0.3-next.12](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.11...data-json-path-v0.0.3-next.12) (2026-02-25)
67
+
68
+
69
+ ### Miscellaneous Chores
70
+
71
+ * **data-json-path:** Synchronize repo versions
72
+
73
+ ## [0.0.3-next.11](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.10...data-json-path-v0.0.3-next.11) (2026-02-25)
74
+
75
+
76
+ ### Miscellaneous Chores
77
+
78
+ * **data-json-path:** Synchronize repo versions
79
+
80
+ ## [0.0.3-next.10](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.9...data-json-path-v0.0.3-next.10) (2026-02-24)
81
+
82
+
83
+ ### Miscellaneous Chores
84
+
85
+ * **data-json-path:** Synchronize repo versions
86
+
87
+ ## [0.0.3-next.9](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.8...data-json-path-v0.0.3-next.9) (2026-02-23)
88
+
89
+
90
+ ### Miscellaneous Chores
91
+
92
+ * **data-json-path:** Synchronize repo versions
93
+
94
+ ## [0.0.3-next.8](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.7...data-json-path-v0.0.3-next.8) (2026-02-02)
95
+
96
+
97
+ ### Features
98
+
99
+ * add json path set and delete methods ([#39](https://github.com/iotaledger/twin-data/issues/39)) ([04b73f3](https://github.com/iotaledger/twin-data/commit/04b73f3d44525f7d3a5d01b56530ff8d9c7bd938))
100
+
101
+ ## [0.0.3-next.7](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.6...data-json-path-v0.0.3-next.7) (2026-01-21)
102
+
103
+
104
+ ### Miscellaneous Chores
105
+
106
+ * **data-json-path:** Synchronize repo versions
107
+
108
+ ## [0.0.3-next.6](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.5...data-json-path-v0.0.3-next.6) (2026-01-14)
109
+
110
+
111
+ ### Miscellaneous Chores
112
+
113
+ * **data-json-path:** Synchronize repo versions
114
+
115
+ ## [0.0.3-next.5](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.4...data-json-path-v0.0.3-next.5) (2026-01-14)
116
+
117
+
118
+ ### Miscellaneous Chores
119
+
120
+ * **data-json-path:** Synchronize repo versions
121
+
122
+ ## [0.0.3-next.4](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.3...data-json-path-v0.0.3-next.4) (2026-01-06)
123
+
124
+
125
+ ### Miscellaneous Chores
126
+
127
+ * **data-json-path:** Synchronize repo versions
128
+
129
+ ## [0.0.3-next.3](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.2...data-json-path-v0.0.3-next.3) (2026-01-05)
130
+
131
+
132
+ ### Miscellaneous Chores
133
+
134
+ * **data-json-path:** Synchronize repo versions
135
+
136
+ ## [0.0.3-next.2](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.1...data-json-path-v0.0.3-next.2) (2025-11-24)
4
137
 
5
138
 
6
139
  ### Bug Fixes
7
140
 
8
- * extraneous type ([0b5d5c6](https://github.com/twinfoundation/data/commit/0b5d5c6980a07018e6f6bedfae4b3bf55c5de8dc))
141
+ * extraneous type ([0b5d5c6](https://github.com/iotaledger/twin-data/commit/0b5d5c6980a07018e6f6bedfae4b3bf55c5de8dc))
9
142
 
10
- ## [0.0.3-next.1](https://github.com/twinfoundation/data/compare/data-json-path-v0.0.3-next.0...data-json-path-v0.0.3-next.1) (2025-11-10)
143
+ ## [0.0.3-next.1](https://github.com/iotaledger/twin-data/compare/data-json-path-v0.0.3-next.0...data-json-path-v0.0.3-next.1) (2025-11-10)
11
144
 
12
145
 
13
146
  ### Features
14
147
 
15
- * add context id features ([#25](https://github.com/twinfoundation/data/issues/25)) ([6592f2e](https://github.com/twinfoundation/data/commit/6592f2e4e59021cc42a079a4f46242758a54313d))
16
- * json path handler ([#24](https://github.com/twinfoundation/data/issues/24)) ([467a0a7](https://github.com/twinfoundation/data/commit/467a0a7e5b7b93d4242ab0f27d042a566bfa6b68))
148
+ * add context id features ([#25](https://github.com/iotaledger/twin-data/issues/25)) ([6592f2e](https://github.com/iotaledger/twin-data/commit/6592f2e4e59021cc42a079a4f46242758a54313d))
149
+ * json path handler ([#24](https://github.com/iotaledger/twin-data/issues/24)) ([467a0a7](https://github.com/iotaledger/twin-data/commit/467a0a7e5b7b93d4242ab0f27d042a566bfa6b68))
17
150
 
18
- ## [0.0.2-next.4](https://github.com/twinfoundation/data-processing/compare/data-json-path-v0.0.2-next.3...data-json-path-v0.0.2-next.4) (2025-11-06)
151
+ ## [0.0.2-next.4](https://github.com/iotaledger/twin-data-processing/compare/data-json-path-v0.0.2-next.3...data-json-path-v0.0.2-next.4) (2025-11-06)
19
152
 
20
153
 
21
154
  ### Features
package/docs/examples.md CHANGED
@@ -1 +1,60 @@
1
- # @twin.org/data-json-path - Examples
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
 
@@ -170,3 +170,61 @@ True if the syntax is valid.
170
170
  #### Throws
171
171
 
172
172
  GeneralError if the path is invalid or data cannot be queried.
173
+
174
+ ***
175
+
176
+ ### setAtLocation() {#setatlocation}
177
+
178
+ > `static` **setAtLocation**(`root`, `location`, `value`): `void`
179
+
180
+ Set a value on the target object using a JSONPath location.
181
+
182
+ #### Parameters
183
+
184
+ ##### root
185
+
186
+ `unknown`
187
+
188
+ The target root object.
189
+
190
+ ##### location
191
+
192
+ [`IJsonPathLocation`](../type-aliases/IJsonPathLocation.md)
193
+
194
+ The JSONPath location tokens.
195
+
196
+ ##### value
197
+
198
+ `unknown`
199
+
200
+ The value to set.
201
+
202
+ #### Returns
203
+
204
+ `void`
205
+
206
+ ***
207
+
208
+ ### deleteAtLocation() {#deleteatlocation}
209
+
210
+ > `static` **deleteAtLocation**(`root`, `location`): `void`
211
+
212
+ Delete a value on the target object using a JSONPath location.
213
+
214
+ #### Parameters
215
+
216
+ ##### root
217
+
218
+ `unknown`
219
+
220
+ The target root object.
221
+
222
+ ##### location
223
+
224
+ [`IJsonPathLocation`](../type-aliases/IJsonPathLocation.md)
225
+
226
+ The JSONPath location tokens.
227
+
228
+ #### Returns
229
+
230
+ `void`
@@ -7,3 +7,7 @@
7
7
  ## Interfaces
8
8
 
9
9
  - [IJsonPathResult](interfaces/IJsonPathResult.md)
10
+
11
+ ## Type Aliases
12
+
13
+ - [IJsonPathLocation](type-aliases/IJsonPathLocation.md)
@@ -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,15 +12,15 @@ The value at the matched path.
12
12
 
13
13
  ***
14
14
 
15
- ### location
15
+ ### location {#location}
16
16
 
17
- > **location**: (`string` \| `number`)[]
17
+ > **location**: [`IJsonPathLocation`](../type-aliases/IJsonPathLocation.md)
18
18
 
19
19
  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
 
@@ -0,0 +1,5 @@
1
+ # Type Alias: IJsonPathLocation
2
+
3
+ > **IJsonPathLocation** = (`string` \| `number`)[]
4
+
5
+ Result paths from a JSONPath query operation.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/data-json-path",
3
- "version": "0.0.3-next.2",
4
- "description": "JSONPath abstraction layer for TWIN platform",
3
+ "version": "0.0.3-next.21",
4
+ "description": "A consistent JSONPath query abstraction.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/data.git",
7
+ "url": "git+https://github.com/iotaledger/data.git",
8
8
  "directory": "packages/data-json-path"
9
9
  },
10
10
  "contributors": [
@@ -50,7 +50,7 @@
50
50
  "conversion"
51
51
  ],
52
52
  "bugs": {
53
- "url": "git+https://github.com/twinfoundation/data/issues"
53
+ "url": "git+https://github.com/iotaledger/data/issues"
54
54
  },
55
55
  "homepage": "https://twindev.org"
56
56
  }