ArrayToJSON

Typefunction
DictionaryLCS
LibraryLiveCode Script
Syntax
ArrayToJSON(<pArray>,<pForceRootType>,<pPretty>)
Associationsws.goulding.script-library.mergjson
Summary

Parse a LiveCode array to JSON

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
Example
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
Values
NameTypeDescription
return

A UTF8 encoded JSON string

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.