textutils.serializeJSON

From ComputerCraft Wiki
Revision as of 20:41, 16 February 2015 by MKlegoman357 (Talk | contribs) (Created page with "{{lowercase}} {{Function |name=textutils.serializeJSON |args={{type|table}}/{{type|string}}/{{type|number}}/{{type|boolean}} data |returns={{type|string}} serializedData |desc...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Grid Redstone.png  Function textutils.serializeJSON
Returns a JSON representation of the data data in a form of a string, mainly for command usage. There is a special key in textutils table: textutils.EMPTY_ARRAY which represents an empty JSON array ( [ ] ). You can use it to serialize an empty JSON array inside, for example a table.


Also exists as textutils.serialiseJSON. Requires CC 1.7 or later.
Syntax textutils.serializeJSON(table/string/number/boolean data)
Returns string serializedData
Part of ComputerCraft
API textutils

Examples

Grid paper.png  Example
Serializes a table into JSON and prints it.
Code
local myTable = {
  key = "value",
  anotherKey = true,
  number = 5,
  array = {1, 2, 3},
  emptyArray = textutils.EMPTY_ARRAY
}

print( textutils.serializeJSON( myTable ) )
Output {"key":"value","anotherKey":true,"number":5,"array":[1,2,3],"emptyArray":[]}