minetest.write_json

From Minetest Developer Wiki
Jump to: navigation, search

Syntax

minetest.write_json(data[, styled])

Description

Returns a string or nil and an error message.

  • Converts a Lua table into a JSON string
  • styled: Outputs in a human-readable format if this is set, defaults to false
  • Un-serializable things like functions and userdata are saved as null.
  • Warning: JSON is more strict than the Lua table format.
  1. You can only use strings and positive integers of at least one as keys.
  2. You can not mix string and integer keys.
This is due to the fact that Javascript has two distinct array and object values.

Example

minetest.write_json({10, {a = false}}) -- returns "[10, {\"a\": false}]"
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox