Json expression to specify data from body

Hey team,

i’m giving N8N another try…, I noticed this has been asked ( and probalby solved a few times in the forums. ). But I still can’t see to get the right json expression.

I’m receiving some json ( by webhook ).
The json seems valid, atleast the json lint website says it is.

When I set the json command : {{ $json[“body”] }}

It give the information of the complete body.
But how can I filter this to just get for example ticker, or tf.

Thank you in advance,

Jack

Information on your n8n setup

  • **n8n version:latest stable
  • **Database (default: SQLite):default
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):docker
  • **Operating system:ubuntu 22.04

@mr.dipp , there are two expression types you could use to achieve this

  1. Bracket notation: {{ $json["body"]["ticker"] }}
  2. Dot notation: {{ $json.body.ticker }}

Hey, thank you for the reply.
I found these examples also in the documentation.

However on both I get an :

Result undefined.

So i’m missing something…

This is the ‘complete’ json received by the webhook.
Minus the ip information.

[

{

“headers”: {

“host”: “”,

“user-agent”: “Go-http-client/1.1”,

“content-length”: “391”,

“accept-encoding”: “gzip”,

“content-type”: “text/plain; charset=utf-8”,

“x-forwarded-for”: “”,

“x-forwarded-host”: “”,

“x-forwarded-port”: “443”,

“x-forwarded-proto”: “https”,

“x-forwarded-server”: “”,

“x-real-ip”: “”

},

“params”: {

},

“query”: {

},

“body”: “{ “alert”: “Custom step condition triggered”, “ticker”: “TURBOUSDT.P”, “tf”: “15S”, “ohlcv”:{ “open”: 0.0046815, “high”: 0.0046895, “low”: 0.0046713, “close”: 0.004672, “volume”: 24239.091, “order block buy volume”: {ob_buy_volume}, “order block sell volume”: {ob_sell_volume}, “order block total volume”: {ob_volume} }, “bartime”: 1716726300000 }”,

“webhookUrl”: “https://webhook…nu/webhook-test/blablabla”,

“executionMode”: “test”

}

]

@mr.dipp , the value of body in your screenshot is a string representation of JSON, not JSON as such. You need to convert the string to JSON first.

{{ JSON.parse($json["body"])["ticker"] }}

Hey Ihortom,

Again thank you for your reply.
I was actually googling and reading up in n8n forms to something similiar.

But I don’t quite get the complete string… , for the json / JSON.parser.

Is the last one a seperate one. Or does it need to be combined with the earlier example(s) ?

When just entering the {{ JSON.parse($json[“body”])[“ticker”] }} , it gives the undefined again.

Is there a specific format I should use for the expression engine in n8n ? Or is it regular / common json ?

thank you ,

Dipp

@mr.dipp , it has to be a regular JSON. From what I see in your screenshot, it is not actually a JSON. Are you sure that is what your webhook node receives?

{ 
  "alert": "Custom step condition triggered", 
  "ticker": "TURBOUSDT.P", 
  "tf": "15S", 
  "ohlcv":{ 
    "open": 0.0046815, 
    "high": 0.0046895, 
    "low": 0.0046713, 
    "close": 0.004672, 
    "volume": 24239.091, 
    "order block buy volume": {ob_buy_volume},     // This will break parsing
    "order block sell volume": {ob_sell_volume},   // This will break parsing
    "order block total volume": {ob_volume}        // This will break parsing
  }, 
  "bartime": 1716726300000
}

If that is so, you might need to use RegEx to extract specific values. Alternatively, replace the offending properties first (ob_buy_volume, ob_sell_volume, ob_volume) with valid ones and then parse the string.

For example,

Goodmorning,

thank you this works :).

Learned a bit more about json.

Thank you for your time and support.

This one can be closed.

Cheers,

Dipp

small update before it can be closed.

Removed the values which had no data from the alert.

And now the values are selectable direct from the expression builder.

Thanks !

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