/
json-multi-schema-transformer.html
86 lines (83 loc) · 2.68 KB
/
json-multi-schema-transformer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script type="text/javascript">
/* global RED:false */
RED.nodes.registerType('json-multi-schema-transformer', {
category: 'function',
color: '#00B4FF',
defaults: {
name: { value: '' },
defaultSchemaUrl: { value: '' },
},
inputs: 1,
outputs: 1,
icon: 'function.png',
label: function () {
return this.name || 'json-multi-schema-transformer';
},
});
</script>
<script type="text/x-red" data-template-name="json-multi-schema-transformer">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row">
<label for="node-input-defaultSchemaUrl"><i class="icon-tag"></i> Default Schema URL</label>
<input type="text" id="node-input-defaultSchemaUrl" placeholder="defaultSchemaUrl" />
</div>
</script>
<script type="text/x-red" data-help-name="json-multi-schema-transformer">
<p>Node to transform a JSON observation to another format using a configurable set of JSONata rules.</p>
<ul>
<li>The node will transform a given JSON payload received in <code>msg.payload</code> using some JSONata rules, which URL is given in <code>msg.schemaUrl</code>.<br />
Alternatively, a static default value for the schema URL can be set in the corresponding property.</li>
<li>If any transformation is actually performed, the URL of the corresponding JSONata file is returned in <code>msg.transformUrl</code>.</li>
<li>The transformed payload is returned in <code>msg.payload</code>. If no <code>msg.schemaUrl</code> is provided, no transformation is performed.</li>
<li>Errors are returned on <code>msg.error</code></li>
</ul>
<p>Example of file containing the list of transformations:</p>
<pre>
[
{
"query": "type='BasicVehicle' and latitude",
"cases": {
"true": "https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/main/examples/OldVehicleToVehicle.jsonata.js"
}
},
{
"query": "type='WeatherObserved' and latitude and longitude",
"cases": {
"true": "https://raw.githubusercontent.com/alexandrainst/node-red-contrib-json-multi-schema/main/examples/OldWeatherObservedToVehicle.jsonata.js"
}
}
]
</pre>
<p>Example of JSONata transformation file:</p>
<pre>
{
"id": id,
"type": "Vehicle",
"vehicleType": vehicleType,
"category": [
category1
],
"location": {
"type": "Point",
"coordinates": [
longitude,
latitude
]
},
"name": name,
"speed": speed,
"cargoWeight": cargoWeight,
"serviceStatus": serviceStatus,
"serviceProvided": [
serviceProvided1,
serviceProvided2
],
"areaServed": areaServed,
"refVehicleModel": refVehicleModel,
"vehiclePlateIdentifier": vehiclePlateIdentifier
}
</pre>
</script>