Hello,
I didn’t find the exact same situation that causes problems in this community forum, so I dare to share with you my problem
I’ve a n8n webhook that receives “Text/Plain” data via POST method.
This webhook gives me JSON formatted data, with of course header
informations, empty param
, empty query
, and a pure string body
:
[
{
"headers": {
"host": "URL",
"user-agent": "Go-http-client/1.1",
"content-length": "120",
"accept-encoding": "gzip",
"content-type": "text/plain; charset=utf-8",
"x-forwarded-for": "IP",
"x-forwarded-host": "URL",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
"x-forwarded-server": "09e57e6daf5b",
"x-real-ip": "IP"
},
"params": {
},
"query": {
},
"body": "{bin:"ABCDEF",time:1653913941.385,val1:40,val2:50,val3:60,val4:70,val5:80}"
}
]
I’d like to convert the string body into JSON.
I found community posts sharing nice Functions module code trying to convert the string
in body but it always fails. I think that’s because there are no { ... }
for the body
line.
I can retrieve params (or query, even though they are empty) using items[0].json.params
but using items[0].json.body
fails, so using JSON.parse() function isn’t even possible.
Do you have suggestion(s) for me please ?
Thank you !!