You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Context*: Node-RED node, or command line with `node ./index.js json-multi-schema-resolver --mappingsUrl='"https://..."'`
35
34
**Purpose*: Ability to determine the URL of the JSON Schema (e.g. FIWARE NGSI) or JSONata expression to use for a given JSON payload received.
36
35
**Configuration*: A Node-RED `mappingsUrl` property to indicate the URL of a file listing which JSON Schema or JSONata expression to use for which data input. (See examples below).
37
36
**Input*: A JSON observation (e.g. one of the FIWARE NGSI types) in the `msg.payload` property.
38
37
**Output*: The unmodified JSON observation in the `msg.payload` property, and the resolved schema URL in the `msg.schemaUrl` property (if any match was found), and potential resolution errors in the `msg.error` property.
39
38
40
-
### Example of input data
39
+
### Example of input data (schema-resolver)
40
+
41
41
This is an example of [standard payload](https://fiware-datamodels.readthedocs.io/en/latest/Transportation/Vehicle/Vehicle/doc/spec/index.html), for which we need to look-up the [corresponding JSON Schema](https://smart-data-models.github.io/data-models/specs/Transportation/Vehicle/VehicleModel/schema.json).
42
42
43
43
We represent the example as a full Node-RED message, i.e. wrapped into a `{"payload":...}` structure.
@@ -119,6 +119,7 @@ In the example, this JSON file is hosted at [`examples/smart-data-transforms.jso
119
119
```
120
120
121
121
### Example of schema resolution from command line
122
+
122
123
The JSON input messages must each be on one single line, and wrapped into a Node-RED structure `{"payload":...}`
123
124
See the `jq` examples at the bottom on how to automatise the wrapping.
124
125
@@ -163,13 +164,10 @@ Output:
163
164
}
164
165
```
165
166
166
-
167
-
168
167
---
169
168
170
-
171
-
172
169
## node-red-contrib-json-multi-schema-transformer
170
+
173
171
**Context*: Node-RED node, or command line with `node ./index.js multi-schema-transformer`
174
172
**Purpose*: Ability to transform a JSON observation on the fly from whichever format to another format (e.g. one of the FIWARE NGSI types) using a specified JSONata URL. Schemas are automatically downloaded and cached the first time they are needed.
175
173
**Input*: A JSON observation in whichever format in the `msg.payload` property, and the corresponding JSONata URL on the `msg.schemaUrl` property (coming from json-multi-schema-resolver).
@@ -180,7 +178,7 @@ Output:
180
178
181
179
It is typically used with a *json-multi-schema-resolver* node in front.
182
180
183
-
### Example of input data
181
+
### Example of input data (schema-transformer)
184
182
185
183
This is an example of proprietary format, which we would like to transform into another format (a standard NGSI one).
186
184
@@ -231,6 +229,7 @@ In the example, this JSONata file is hosted at [`Cesva-TA120-to-NoiseLevelObserv
231
229
A more advanced example of JSONata transformation can be found in [`NGSI-Normalised-to-keyValues.jsonata.js`](https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/master/examples/NGSI-Normalised-to-keyValues.jsonata.js).
232
230
233
231
### Example of transformation from command line
232
+
234
233
The JSON input messages must each be on one single line, and wrapped into a Node-RED structure `{"payload":...}`
235
234
236
235
```sh
@@ -241,7 +240,7 @@ jq .
241
240
242
241
Same example, but using a static default value for the schema URL in the corresponding property:
**Context*: Node-RED node, or command line with `node ./index.js json-multi-schema-validator`
281
277
**Purpose*: Ability to validate a JSON observation (e.g. one of the FIWARE NGSI types) on the fly against a specified JSON Schema URL. Schemas are automatically downloaded and cached the first time they are needed.
282
278
**Input*: A JSON observation (e.g. one of the FIWARE NGSI types) in the `msg.payload` property, and the corresponding JSON Schema URL on the `msg.schemaUrl` property (coming from json-multi-schema-resolver).
@@ -286,7 +282,8 @@ Output:
286
282
287
283
It is typically used with a *json-multi-schema-resolver* node in front.
288
284
289
-
### Example of input data
285
+
### Example of input data (schema-validator)
286
+
290
287
This is an example of [standard payload](https://fiware-datamodels.readthedocs.io/en/latest/Environment/NoiseLevelObserved/doc/spec/index.html#noise-level-observed), which we want to validate against its [corresponding JSON Schema](https://smart-data-models.github.io/data-models/specs/Environment/NoiseLevelObserved/schema.json), which address is provided by the Node-RED property `msg.schemaUrl`.
291
288
292
289
```json
@@ -310,6 +307,7 @@ This is an example of [standard payload](https://fiware-datamodels.readthedocs.i
310
307
```
311
308
312
309
### Example of JSON Schema validation from command line
310
+
313
311
The JSON input messages must each be on one single line, and wrapped into a Node-RED structure `{"payload":...}`
314
312
315
313
```sh
@@ -341,20 +339,19 @@ Output:
341
339
}
342
340
```
343
341
344
-
345
-
346
342
---
347
343
348
-
349
-
350
344
## Wiring/Piping all modules together
345
+
351
346
The three modules above may be used independently or in combination.
352
347
Here is an example of JSON transformation, followed by a schema resolver, and finally a JSON Schema validation.
The three nodes are all expecting configuration files and corresponding schemas to be provided by HTTP.
444
434
445
-
While JSON Schemas are often publicly available (e.g. https://schema.org , https://smart-data-models.github.io/data-models/ ), it might not be the case for the list of JSON Schemas itself, the list of transformations, or the JSONata transformations.
435
+
While JSON Schemas are often publicly available (e.g. <https://schema.org> , <https://smart-data-models.github.io/data-models/> ), it might not be the case for the list of JSON Schemas itself, the list of transformations, or the JSONata transformations.
446
436
447
437
Any HTTP server can be used to host those documents. This can also be done using Node-RED:
448
438
@@ -458,12 +448,8 @@ In this example, the schemas are published at `http://localhost:1880/schemas/exa
458
448
459
449
Read more on the [Node-RED cookbook](https://cookbook.nodered.org/http/serve-json-content).
460
450
461
-
462
-
463
451
---
464
452
465
-
466
-
467
453
## Caching of schemas
468
454
469
455
A disk copy of the downloaded JSON and JSONata documents is kept in cache on disk.
0 commit comments