Selec a value from a variable key

Hi guys. I have thie Json Payload.

{
"total": "1",
"contacts": {
"5734": {
"isPublished": true,
"dateAdded": "2020-10-05T13:51:52+00:00",
"dateModified": "2020-12-02T23:10:17+00:00",
"createdBy": null,
"createdByUser": null,
"modifiedBy": 3,
"modifiedByUser": "Leo Borlot",
"id": 5734,
"points": 0,
"color": null,
"fields": {
"core": {
"points": {
"id": "9",
"label": "Points",
"alias": "points",
"type": "number",
"group": "core",
"object": "lead",
"is_fixed": "1",
"properties": "a:0:{}",
"default_value": null,
"value": "0",
"normalizedValue": "0"
},

How May I selec the point.id if I don´t know whit is the value of contact number?
Ive try this: payload.contacts[0].fields.core.points.id
But it, dont works...

Sorry if this is very newbie...

There is a json query library called Jsonata that can be accessed through the Change node.
In cases like your example it is very very useful.

You can use **.points.id as an expression that basically filters out all points.id values from your Json at any level deep. hence the ** wildcards.

Example:

[{"id":"fc99ef62.bb6938","type":"debug","z":"f19dd631.0088b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":460,"wires":[]},{"id":"b5689c00.f84178","type":"inject","z":"f19dd631.0088b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"total\":\"1\",\"contacts\":{\"5734\":{\"isPublished\":true,\"dateAdded\":\"2020-10-05T13:51:52+00:00\",\"dateModified\":\"2020-12-02T23:10:17+00:00\",\"createdBy\":null,\"createdByUser\":null,\"modifiedBy\":3,\"modifiedByUser\":\"Leo Borlot\",\"id\":5734,\"points\":0,\"color\":null,\"fields\":{\"core\":{\"points\":{\"id\":\"9\",\"label\":\"Points\",\"alias\":\"points\",\"type\":\"number\",\"group\":\"core\",\"object\":\"lead\",\"is_fixed\":\"1\",\"properties\":\"a:0:{}\",\"default_value\":null,\"value\":\"0\",\"normalizedValue\":\"0\"}}}}}}","payloadType":"json","x":240,"y":460,"wires":[["1718a348.eb841d","5186e917.73bd28"]]},{"id":"1718a348.eb841d","type":"change","z":"f19dd631.0088b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"**.points.id","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":460,"wires":[["fc99ef62.bb6938"]]},{"id":"5186e917.73bd28","type":"debug","z":"f19dd631.0088b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":380,"y":360,"wires":[]}]

You can read more on JSONata operators here

1 Like

Thanks man, this is all new for me, I will learn more about JSONATA.

Your sugestion works very well here!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.