toJSON
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
This function converts a single value (preferably a Lua table) into a JSON encoded string. You can use this to store the data and then load it again using fromJSON.
When using toJSON for submitting data using fetchRemote for example, make sure to use string.sub(data, 2, -2) to remove the brackets as many APIs will not understand the request
Due to technical limitations (partly of json-c) the stringified keys will be truncated to the first 255 characters
Syntax
string toJSON ( var value, [ bool compact = false, string prettyType = "none" ] )Required Arguments
- value: MISSING_PARAM_DESC
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- compact (default: false): a boolean representing whether the string will contain whitespaces. To remove whitespaces from JSON string, use true . String will contain whitespaces per default.
- prettyType (default: "none"): MISSING_PARAM_DESC
Returns
- string: value
Returns a JSON formatted string.
Code Examples
This example shows how you can encode an array. The string json should equal"[ { "1": "dogs", "mouse": "food", "cat": "hungry", "birds": 4 } ]" after executed.
local json = toJSON ( { "dogs", cat = "hungry", mouse = "food", birds = 4 } )See Also
Utility Functions
- addDebugHook
- bitAnd
- bitArShift
- bitExtract
- bitLRotate
- bitLShift
- bitNot
- bitOr
- bitReplace
- bitRRotate
- bitRShift
- bitTest
- bitXor
- createTrayNotification
- debugSleep
- decodeString
- deref
- downloadFile
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getFPSLimit
- getKeyboardLayout
- getLocalization
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getProcessMemoryStats
- getRealTime
- getServerIp
- getTickCount
- getTimerDetails
- getTimers
- gettok
- getUserdataType
- getVersion
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isShowCollisionsEnabled
- isShowSoundEnabled
- isTimer
- isTimerPaused
- isTransferBoxAlwaysVisible
- isTransferBoxVisible
- isTrayNotificationEnabled
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- ref
- removeDebugHook
- resetTimer
- setClipboard
- setDevelopmentMode
- setFPSLimit
- setTimer
- setTimerPaused
- setTransferBoxVisible
- setWindowFlashing
- sha256
- showCol
- showSound
- split
- teaDecode
- teaEncode
- tocolor
- toJSON
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub