Groovy web console

subscribe to the feed Subscribe
to this
site

json-wa

Published 1 month ago by mk
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def message = '''This is supposed to contain some "double quotes"
                    and line breaks.'''

text = new groovy.json.JsonBuilder(message).toString()
println(text)
text = text.substring( 1, text.length() - 1 )
println(text)

def msg = new groovy.json.JsonSlurperClassic().parseText """
{ "text": "${text}",
  "title": "foo",
  "themeColor": "bar"
}
"""

println(msg)