Search into payload.items(i).description

With a msg.payload like the following:


How do I get only payload.items[i].description matching a search term ("team1" or "team2" in this case)?

Without a example JSON (image does not help) I can only offer a JSONata expression,. This can be used in the change node by selection J: expression type input
set msg.payload
to J: the expression

$$.payload.items[$contains($.description,/team1|team2/)]

If you require an example please supply a JSON in text form

Here an example JSON

{
    "kind": "calendar#events",
    "etag": "\"someetag\"",
    "summary": "mycalendar",
    "description": "",
    "updated": "2024-11-20T00:44:26.875Z",
    "timeZone": "America/New_York",
    "accessRole": "owner",
    "defaultReminders": [
    ],
    "nextPageToken": "Cj8KLwotCgsIgfXJuQYQgICJehIeChwKGjlybjdlbWhwa3Nv-------aHJnMzgxNWVmGgwI6uH0uQYQwOGdoQPAPgE=",
    "items": [
        {
            "kind": "calendar#event",
            "etag": "\"someetag\"",
            "id": "m94he3apgrub3b6osupai21u0m",
            "status": "confirmed",
            "htmlLink": "https://www.google.com/calendar/event?eid=bTk0aG-----------------GlhbGJpdHJlc0Bt",
            "created": "2019-04-18T22:31:10.000Z",
            "updated": "2021-07-23T14:20:04.475Z",
            "summary": "Customer 1",
            "description": "team:team1",
            "location": "some address",
            "colorId": "9",
            "creator": {
                "email": "someone@gmail.com",
                "self": true
            },
            "organizer": {
                "email": "someone@gmail.com",
                "self": true
            },
            "start": {
                "dateTime": "2021-07-31T09:45:00-04:00",
                "timeZone": "America/New_York"
            },
            "end": {
                "dateTime": "2021-07-31T11:30:00-04:00",
                "timeZone": "America/New_York"
            },
            "recurrence": [
                "RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=4;BYDAY=SA"
            ],
            "iCalUID": "someone@google.com",
            "sequence": 21,
            "extendedProperties": {
                "private": {
                    "everyoneDeclinedDismissed": "-1"
                }
            },
            "reminders": {
                "useDefault": true
            },
            "eventType": "default"
        },
		{
            "kind": "calendar#event",
            "etag": "\"someetag\"",
            "id": "someid",
            "status": "confirmed",
            "htmlLink": "https://www.google.com/calendar/event?eid=bTk0aG-----------------GlhbGJpdHJlc0Bt",
            "created": "2019-04-18T22:31:10.000Z",
            "updated": "2021-07-23T14:20:04.475Z",
            "summary": "Customer 2",
            "description": "team:team2",
            "location": "some address",
            "colorId": "10",
            "creator": {
                "email": "someone@gmail.com",
                "self": true
            },
            "organizer": {
                "email": "someone@gmail.com",
                "self": true
            },
            "start": {
                "dateTime": "2021-07-30T09:45:00-04:00",
                "timeZone": "America/New_York"
            },
            "end": {
                "dateTime": "2021-07-30T11:30:00-04:00",
                "timeZone": "America/New_York"
            },
            "recurrence": [
                "RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=4;BYDAY=SA"
            ],
            "iCalUID": "someone@google.com",
            "sequence": 21,
            "extendedProperties": {
                "private": {
                    "everyoneDeclinedDismissed": "-1"
                }
            },
            "reminders": {
                "useDefault": true
            },
            "eventType": "default"
        }
    ]
}

Here are some examples

[{"id":"20e9cd21c919eddd","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"kind\":\"calendar#events\",\"etag\":\"\\\"someetag\\\"\",\"summary\":\"mycalendar\",\"description\":\"\",\"updated\":\"2024-11-20T00:44:26.875Z\",\"timeZone\":\"America/New_York\",\"accessRole\":\"owner\",\"defaultReminders\":[],\"nextPageToken\":\"Cj8KLwotCgsIgfXJuQYQgICJehIeChwKGjlybjdlbWhwa3Nv-------aHJnMzgxNWVmGgwI6uH0uQYQwOGdoQPAPgE=\",\"items\":[{\"kind\":\"calendar#event\",\"etag\":\"\\\"someetag\\\"\",\"id\":\"m94he3apgrub3b6osupai21u0m\",\"status\":\"confirmed\",\"htmlLink\":\"https://www.google.com/calendar/event?eid=bTk0aG-----------------GlhbGJpdHJlc0Bt\",\"created\":\"2019-04-18T22:31:10.000Z\",\"updated\":\"2021-07-23T14:20:04.475Z\",\"summary\":\"Customer 1\",\"description\":\"team:team1\",\"location\":\"some address\",\"colorId\":\"9\",\"creator\":{\"email\":\"someone@gmail.com\",\"self\":true},\"organizer\":{\"email\":\"someone@gmail.com\",\"self\":true},\"start\":{\"dateTime\":\"2021-07-31T09:45:00-04:00\",\"timeZone\":\"America/New_York\"},\"end\":{\"dateTime\":\"2021-07-31T11:30:00-04:00\",\"timeZone\":\"America/New_York\"},\"recurrence\":[\"RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=4;BYDAY=SA\"],\"iCalUID\":\"someone@google.com\",\"sequence\":21,\"extendedProperties\":{\"private\":{\"everyoneDeclinedDismissed\":\"-1\"}},\"reminders\":{\"useDefault\":true},\"eventType\":\"default\"},{\"kind\":\"calendar#event\",\"etag\":\"\\\"someetag\\\"\",\"id\":\"someid\",\"status\":\"confirmed\",\"htmlLink\":\"https://www.google.com/calendar/event?eid=bTk0aG-----------------GlhbGJpdHJlc0Bt\",\"created\":\"2019-04-18T22:31:10.000Z\",\"updated\":\"2021-07-23T14:20:04.475Z\",\"summary\":\"Customer 2\",\"description\":\"team:team2\",\"location\":\"some address\",\"colorId\":\"10\",\"creator\":{\"email\":\"someone@gmail.com\",\"self\":true},\"organizer\":{\"email\":\"someone@gmail.com\",\"self\":true},\"start\":{\"dateTime\":\"2021-07-30T09:45:00-04:00\",\"timeZone\":\"America/New_York\"},\"end\":{\"dateTime\":\"2021-07-30T11:30:00-04:00\",\"timeZone\":\"America/New_York\"},\"recurrence\":[\"RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=4;BYDAY=SA\"],\"iCalUID\":\"someone@google.com\",\"sequence\":21,\"extendedProperties\":{\"private\":{\"everyoneDeclinedDismissed\":\"-1\"}},\"reminders\":{\"useDefault\":true},\"eventType\":\"default\"}]}","payloadType":"json","x":170,"y":7540,"wires":[["fc83a3ec18010038","7088c34e07e49428","3c0dfcc5c07dddf0"]]},{"id":"fc83a3ec18010038","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.items[$contains($.description,/team1|team2/)]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":7540,"wires":[["8c2bf131d1114463"]]},{"id":"7088c34e07e49428","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.items[$contains($.description, \"team1\")]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":7620,"wires":[["ca2f643591f1a80e"]]},{"id":"3c0dfcc5c07dddf0","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.items[$contains($.description, \"team1\")].description","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":7700,"wires":[["332b3d80e61b4ee6"]]},{"id":"8c2bf131d1114463","type":"debug","z":"d1395164b4eec73e","name":"debug 2577","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":7540,"wires":[]},{"id":"ca2f643591f1a80e","type":"debug","z":"d1395164b4eec73e","name":"debug 2578","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":7620,"wires":[]},{"id":"332b3d80e61b4ee6","type":"debug","z":"d1395164b4eec73e","name":"debug 2579","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":7700,"wires":[]}]

If not what you are looking for, please provide example output for example input.

1 Like

Thanks for helping a noob, that works! Now the resulting JSON is as follows:

[
    {
        "kind": "calendar#event",
        "etag": "\"------\"",
        "id": "---",
        "status": "confirmed",
        "htmlLink": "https://www.google.com/calendar/event?eid=bTk0aGUzYXBncnViM2-----------",
        "created": "2019-04-18T22:31:10.000Z",
        "updated": "2021-07-23T14:20:04.475Z",
        "summary": "first last",
        "description": "team:team1",
        "location": "12345 Some street",
        "colorId": "9",
        "creator": {
            "email": "someone@gmail.com",
            "self": true
        },
        "organizer": {
            "email": "someone@gmail.com",
            "self": true
        },
        "start": {
            "dateTime": "2021-07-31T09:45:00-04:00",
            "timeZone": "America/New_York"
        },
        "end": {
            "dateTime": "2021-07-31T11:30:00-04:00",
            "timeZone": "America/New_York"
        },
        "recurrence": [
            "RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=4;BYDAY=SA"
        ],
        "iCalUID": "someone@google.com",
        "sequence": 21,
        "extendedProperties": {
            "private": {
                "everyoneDeclinedDismissed": "-1"
            }
        },
        "reminders": {
            "useDefault": true
        },
        "eventType": "default"
    }
]

Now I need to I get just the payload.summary and payload.location, how can I do it?

Help no longer needed! I got it by adding a function node:

for (var i = 0; i < msg.payload.length; i++) {
 var newMsg = {};
 newMsg.payload = msg.payload[i].summary + "|" + msg.payload[i].location;
 node.send(newMsg);
}
return null;

Not everything requires the overhead of calling a function.

If that is the full array then you should be able to use a simple template node

Or if you have multiple items in an array and you require a message for each use a split node first.

example of both

[{"id":"20e9cd21c919eddd","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"kind\":\"calendar#event\",\"etag\":\"\\\"------\\\"\",\"id\":\"---\",\"status\":\"confirmed\",\"htmlLink\":\"https://www.google.com/calendar/event?eid=bTk0aGUzYXBncnViM2-----------\",\"created\":\"2019-04-18T22:31:10.000Z\",\"updated\":\"2021-07-23T14:20:04.475Z\",\"summary\":\"first last\",\"description\":\"team:team1\",\"location\":\"12345 Some street\",\"colorId\":\"9\",\"creator\":{\"email\":\"someone@gmail.com\",\"self\":true},\"organizer\":{\"email\":\"someone@gmail.com\",\"self\":true},\"start\":{\"dateTime\":\"2021-07-31T09:45:00-04:00\",\"timeZone\":\"America/New_York\"},\"end\":{\"dateTime\":\"2021-07-31T11:30:00-04:00\",\"timeZone\":\"America/New_York\"},\"recurrence\":[\"RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=4;BYDAY=SA\"],\"iCalUID\":\"someone@google.com\",\"sequence\":21,\"extendedProperties\":{\"private\":{\"everyoneDeclinedDismissed\":\"-1\"}},\"reminders\":{\"useDefault\":true},\"eventType\":\"default\"}]","payloadType":"json","x":170,"y":7540,"wires":[["7b7dca1f7a4e5cf0","710e1109f794b498"]]},{"id":"7b7dca1f7a4e5cf0","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":330,"y":7540,"wires":[["a2a2a5d366d4c842"]]},{"id":"710e1109f794b498","type":"template","z":"d1395164b4eec73e","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.0.summary}}|{{payload.0.location}}","output":"str","x":340,"y":7620,"wires":[["7d06650d4158e3cd"]]},{"id":"a2a2a5d366d4c842","type":"template","z":"d1395164b4eec73e","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.summary}}|{{payload.location}}","output":"str","x":480,"y":7540,"wires":[["8c2bf131d1114463"]]},{"id":"7d06650d4158e3cd","type":"debug","z":"d1395164b4eec73e","name":"debug 2578","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":7620,"wires":[]},{"id":"8c2bf131d1114463","type":"debug","z":"d1395164b4eec73e","name":"debug 2577","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":7540,"wires":[]}]

You may benifit watching the essentials videos , which are really worth a view to get the basics of node-red

Thank you! I'll definitely watch the videos