From 0b6a48203716cd5c1c75603b7101f144fdc38a5f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 12 Apr 2026 23:13:56 +0200 Subject: [PATCH] Clarify limitations with core.write_json() --- doc/lua_api.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 1180b0c969..668b5fd2bf 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -7994,16 +7994,18 @@ Misc. * Example: `parse_json("[10, {\"a\":false}]")`, returns `{10, {a = false}}` * `core.write_json(data[, styled])`: returns a string or `nil` and an error message. - * Convert a Lua table into a JSON string - * styled: Outputs in a human-readable format if this is set, defaults to - false. + * Convert a value into a JSON string + * `styled`: Outputs in a human-readable format if this is true, defaults to + `false`. * Unserializable things like functions and userdata will cause an error. - * **Warning**: JSON is more strict than the Lua table format. + * **Warning**: JSON is stricter than Lua tables. 1. You can only use strings and positive integers of at least one as keys. 2. You cannot mix string and integer keys. This is due to the fact that JSON has two distinct array and object - values. + types. + 3. Empty tables will be written as `null`, because it's not clear if it + should be a JSON array or object. * Example: `write_json({10, {a = false}})`, returns `'[10, {"a": false}]'` * `core.serialize(table)`: returns a string