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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -