Extracting code

How i can extract this part “test message here” from my API request?:


[
{
"data":
"[{"envelope":{"source":"+4398575490","sourceNumber":"+4398575490","sourceUuid":"22afj3oi4nmfo-8e94-3fa0-a7e4-af6d3cef34c4","sourceName":"Gates","sourceDevice":2,"timestamp":1684596688622,"syncMessage":{"sentMessage":{"destination":null,"destinationNumber":null,"destinationUuid":null,"timestamp":1684596688622,"message":"test message here","expiresInSeconds":0,"viewOnce":false,"groupInfo":{"groupId":"l/EgH4qfkdjn349834f93ff25tiYygqzwjkAgfm349f309lE=","type":"DELIVER"}}}},"account":"+4398575490"}]"
}
]

I already try: $[0].data[0].envelope.syncMessage.sentMessage.message
and
$.data[0].envelope.syncMessage.sentMessage.message and nothing works.

Hey @JabmoBabo,

Welcome to the community :raised_hands:

I would maybe use a set node and set the value to {{ JSON.parse( $json.data ) }} then in the next node you have a better object to work from.

It not works:

But I fix it (gpt fix it) by using Code node and this code:

const message = JSON.parse($node["IF1"].json["data"])[0].envelope.syncMessage.sentMessage.message;
const messageWithoutPrefix = message.replace('/gpt ', '');
return [{ 'messageWithoutPrefix': messageWithoutPrefix }];

IF1 is a previous node.

2 Likes

Forgot to mention you would need to toggle the expression option. But glad you have sorted it :slightly_smiling_face:

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