Add flag option "null_to_table" to convert null values to table in wdata.write

This commit is contained in:
Jordan Irwin 2021-08-28 18:52:01 -07:00
parent af22d136de
commit 3794faca1f
2 changed files with 10 additions and 0 deletions

@ -58,6 +58,7 @@ end
-- --
-- @table FlagsDef -- @table FlagsDef
-- @tfield[opt] bool styled Outputs in a human-readable format if this is set (default: `true`). -- @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. --- Writes to config file in world directory.
@ -97,6 +98,14 @@ function wdata.write(fname, data, flags)
end end
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) return core.safe_file_write(fpath, json_data)
end end

@ -2,6 +2,7 @@
next next
---- ----
- changed wdata.write method to take table parameter "flags" instead of boolean "styled" - 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 v1.1