JMESPath Tester

JMESPath is part of n8n since version 0.167.0

Just in case you want to test it’s queries …

https://api.gopipeline.io/jmespath-tester

3 Likes

How do you reference the json in a function node? I love JMESpath but not sure how to use the new functionality.

Hi @djangelic I haven’t updated to the latest version of n8n yet, so I honestly do not know how this works yet. However, I’ve been playing around with jmespath in VS Code, and there it works as follows:

var jmespath = require("jmespath");

let data = {
  "locations": [
    {"name": "Seattle", "state": "WA"},
    {"name": "New York", "state": "NY"},
    {"name": "Bellevue", "state": "WA"},
    {"name": "Olympia", "state": "WA"}
  ]
}

let result = jmespath.search(data, "locations[].{city: name}")

console.log(result)

And in this example the result is:

[
  { city: 'Seattle' },
  { city: 'New York' },
  { city: 'Bellevue' },
  { city: 'Olympia' }
]

Hi @djangelic apparently it’s already possible in the DeskTop App as JMESPath in already in the nodes modules. You just have to add it to your n8n-desktop environment.

NODE_FUNCTION_ALLOW_EXTERNAL=jmespath

Here’ an example of data transformation:

let data = item

var jmespath = require("jmespath");

let result = jmespath.search(data, "locations[].{city: name}")

return result

And this is an example workflow of this code with sample data:

The only thing you’ve go to do, is replace the QUERY:

let result = jmespath.search(data, "QUERY")

with the code you can find at JMESPath.org

Try for example:

let result = jmespath.search(data, "locations[?state == 'WA'].name | sort(@)[-2:] | {WashingtonCities: join(', ', @)}")

and see what happens :sunglasses:

Enjoy!

Awesome, thanks for the very clear write up! Looking forward to testing it!