textutils.unserialiseJSON

From ComputerCraft
Jump to navigation Jump to search

textutils.unserialiseJSON
Function
Syntax
textutils.unserialiseJSON()
Returns table result
API textutils
Source CC:Tweaked (source)

Load a JSON string into a Lua Table. JSON is used to store multiple variables into a string. It is popular in web APIs, JavaScript scripts, Java programs, and is used to store NBT data in Minecraft blocks and items. JSON arrays can store more arrays, booleans, strings,

Options

textutils.unserialiseJSON has a second argument that can be used for settings when parsing JSON.

  • parse_null Indicates whether nulls will be parsed as null or as nil. When a null is parsed, it is equal to textutils.json_null
ExampleExampleLoad JSON string
Loads a JSON String and prints a key
Code
result = textutils.unserializeJSON('{"Hello":"World"}')
print(result["Hello"])
Output World
ExampleExampleLoad JSON string
Loads a JSON String and prints a key
Code
result = textutils.unserializeJSON('["Hello World"]')
print(result[1])
Output Hello World
ExampleExampleLoad JSON string and parse nulls
Loads a JSON String. null values will be parsed to null instead of nil. null is the same as textutils.json_null
Code
result = textutils.unserializeJSON('{"hello": "world", "foo": null}', {parse_null = true})
print(result["foo"])
Output null