Basic JSON formatting using Mule Expression Language -
when sending post requests address on slack, json needs formatted such:
{"channel": "#testing", "username": "test", "text": "subject"}
or of sort, normal. problem i'm having basic, basically, need send details obtained email via json, this:
{"channel": "#testing", "username": "#[message.inboundproperties['from']]", "text": "subject"}
and when log payload after this, get:
{"channel": "#testing", "username": ""doe, john" <email@address.com>", "text": "subject"}
and throws 500 error code, presumably because no longer valid json (my guess because of weird quotations, if else , this:
{"channel": "#testing", "username": "username", "text": "#[message.payload]"}
gives me this:
{"channel": "#testing", "username": "username", "text": "email body ", "icon_emoji": ":man_with_turban:"}
which looks valid me, not work (perhaps there's new line character or something, it's character in string not?)
i'm not sure how properly.
the preferred approach json generation in mule create datastructure (like map
) , use json:object-to-json-transformer
serialize json. takes care of escaping.
if persist in creating json string, need escape values inject (for example using escapejavascript
).
Comments
Post a Comment