This example shows how you can store an object in a flow variable and then query it using jsonata. This would normally require function nodes but is now possible using jsonata.
-
-
Save natcl/ccc2ca15ded079174b9677b6628a21d9 to your computer and use it in GitHub Desktop.
Using JSONATA to query objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "d001dc53.264018", | |
"type": "template", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"field": "payload", | |
"fieldType": "msg", | |
"format": "yaml", | |
"syntax": "mustache", | |
"template": "canada:\n fruits:\n - bleuet\n - framboise\n légumes:\n - tomate\n - patate\n - navet\nmexique:\n fruits:\n - café\n - orange\n légumes:\n - avocats", | |
"output": "str", | |
"x": 370, | |
"y": 100, | |
"wires": [ | |
[ | |
"9e173897.ccab38" | |
] | |
] | |
}, | |
{ | |
"id": "a631ad2e.febf2", | |
"type": "inject", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"repeat": "", | |
"crontab": "", | |
"once": true, | |
"x": 190, | |
"y": 100, | |
"wires": [ | |
[ | |
"d001dc53.264018" | |
] | |
] | |
}, | |
{ | |
"id": "9e173897.ccab38", | |
"type": "yaml", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"x": 510, | |
"y": 100, | |
"wires": [ | |
[ | |
"588f9990.21743" | |
] | |
] | |
}, | |
{ | |
"id": "588f9990.21743", | |
"type": "change", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "food", | |
"pt": "flow", | |
"to": "payload", | |
"tot": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 670, | |
"y": 100, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "5d6a8619.27e0c8", | |
"type": "inject", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"topic": "", | |
"payload": "repas", | |
"payloadType": "flow", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 180, | |
"y": 300, | |
"wires": [ | |
[ | |
"3f38369a.fed952" | |
] | |
] | |
}, | |
{ | |
"id": "3f38369a.fed952", | |
"type": "debug", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"active": true, | |
"console": "false", | |
"complete": "false", | |
"x": 690, | |
"y": 300, | |
"wires": [] | |
}, | |
{ | |
"id": "249e58ed.5231b8", | |
"type": "inject", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"topic": "", | |
"payload": "mexique", | |
"payloadType": "str", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 180, | |
"y": 380, | |
"wires": [ | |
[ | |
"6d5ef611.7e4c9" | |
] | |
] | |
}, | |
{ | |
"id": "6d5ef611.7e4c9", | |
"type": "change", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload", | |
"pt": "msg", | |
"to": "$lookup($flowContext('food'), payload)", | |
"tot": "jsonata" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 420, | |
"y": 380, | |
"wires": [ | |
[ | |
"3f38369a.fed952" | |
] | |
] | |
}, | |
{ | |
"id": "799e8f63.f79ab8", | |
"type": "inject", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"topic": "", | |
"payload": "canada", | |
"payloadType": "str", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 170, | |
"y": 420, | |
"wires": [ | |
[ | |
"6d5ef611.7e4c9" | |
] | |
] | |
}, | |
{ | |
"id": "ea873589.6832e8", | |
"type": "inject", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"topic": "", | |
"payload": "[\"mexique\", \"fruits\"]", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 210, | |
"y": 520, | |
"wires": [ | |
[ | |
"cc133563.e5759" | |
] | |
] | |
}, | |
{ | |
"id": "cc133563.e5759", | |
"type": "change", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload", | |
"pt": "msg", | |
"to": "$lookup($flowContext('food'), payload[0]) ~> $lookup(payload[1])", | |
"tot": "jsonata" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 420, | |
"y": 520, | |
"wires": [ | |
[ | |
"3f38369a.fed952" | |
] | |
] | |
}, | |
{ | |
"id": "c19fefdd.daac4", | |
"type": "inject", | |
"z": "82c1ad52.7a898", | |
"name": "", | |
"topic": "", | |
"payload": "[\"canada\", \"légumes\"]", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 220, | |
"y": 560, | |
"wires": [ | |
[ | |
"cc133563.e5759" | |
] | |
] | |
}, | |
{ | |
"id": "b434fc1b.4f748", | |
"type": "comment", | |
"z": "82c1ad52.7a898", | |
"name": "Create a complex stucture", | |
"info": "", | |
"x": 210, | |
"y": 40, | |
"wires": [] | |
}, | |
{ | |
"id": "f15b4ee9.993e7", | |
"type": "comment", | |
"z": "82c1ad52.7a898", | |
"name": "Filter the structure", | |
"info": "", | |
"x": 190, | |
"y": 240, | |
"wires": [] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment