Skip to main content

ArrayToJSON

Type​

function

Summary​

Parse a LiveCode array to JSON

Syntax​

ArrayToJSON(<pArray>,<pForceRootType>,<pPretty>)

Description​

By default LiveCode numerically indexed arrays with keys 1...N are translated to JSON arrays and LiveCode array key -> value pairs are translated to JSON objects.

Parameters​

NameTypeDescription

pArray

A LiveCode array

pForceRootType

Force an element value to be represented as a JSON type other than the default

  • "object" - force an object even if the array has numeric 1...N keys
  • "string" - force a string even if the element value parses as a number or boolean

Examples​

local tMessage
ask question "What do you want to send?"
if it is not empty then
put it into tMessage["text"]
put ArrayToJSON(tMessage) into tMessage

set the httpHeaders to "Content-type: application/json"
post tMessage to url kSlackWebhookURL
end if

Value​

NameTypeDescription

return

A UTF8 encoded JSON string

Thank you for your feedback!

Was this page helpful?