diff --git a/api.lua b/api.lua index 3a54323..aa2cd81 100644 --- a/api.lua +++ b/api.lua @@ -58,6 +58,7 @@ end -- -- @table FlagsDef -- @tfield[opt] bool styled Outputs in a human-readable format if this is set (default: `true`). +-- @tfield[opt] bool null_to_table "null" values will be converted to tables in output (default: `false`). --- Writes to config file in world directory. @@ -97,6 +98,14 @@ function wdata.write(fname, data, flags) end end + if flags.null_to_table then + if flags.styled then + json_data = json_data:gsub(": null([,\n])", ": {}%1") + else + json_data = json_data:gsub(":null([,%]}])", ":{}%1") + end + end + return core.safe_file_write(fpath, json_data) end diff --git a/changelog.txt b/changelog.txt index a4d9dc9..299c25c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ next ---- - changed wdata.write method to take table parameter "flags" instead of boolean "styled" +- added flag option "null_to_table" for wdata.write that converts null values to tables v1.1