Using mutate to get a key via a variable

Hi there,
is it possible to get the Mutate node to get a Key via a variable?

image

Something like this (not working):

In a payload path, no, there is no way to insert a variable into the path. But what you can do is use the {{lookup}} helper to reference a value at a variable path in a template.

So, change your “Move a value” operation to a “Set a new value” operation:

  • Value Template: {{lookup (lookup working.query.result.devices working.device.deviceId) 'points'}}
  • Destination Path: working.points

Hi Dylan, think I have a similar problem as this but am having some trouble and all I seem to get back is :

  • “points”:“[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]”

Here is my mutate node:

Corresponding payload structure:

Looks like it is finding the right place but doesn’t like creating an array or points at the destination path.

Yup, since the value you’re looking up there is an object, you need to do two additional things:

  1. Wrap your helper in a {{jsonEncode}} helper like below to retrieve the objects instead of the string “[object Object]”.
  2. Check the “Treat value as JSON” checkbox; otherwise what gets put at data.points will be a stringified result.
{{jsonEncode (lookup (lookup data.currentTrip.trip_data.result.devices data.params.asset_id) 'points')}}
1 Like

Thanks @Dylan_Schuster worked perfectly :smiley: