Fix JSON encoding: force empty tables to encode as arrays
Lua's json.encode produces {} for empty tables instead of [].
Use json.util.InitArray to mark tables as arrays so they encode
correctly as [] for authors, bookmarks, highlights, notes, and books.
This commit is contained in:
@@ -11,6 +11,7 @@ local SpinWidget = require("ui/widget/spinwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local json = require("json")
|
||||
local json_util = require("json/util")
|
||||
local logger = require("logger")
|
||||
local sha2 = require("ffi/sha2")
|
||||
local time = require("ui/time")
|
||||
@@ -670,6 +671,7 @@ function Bookhoard:collectBookData()
|
||||
if props.authors then
|
||||
authors = { props.authors }
|
||||
end
|
||||
json_util.InitArray(authors)
|
||||
|
||||
local file_sha256 = self:getFileSHA256()
|
||||
local book_uuid = self:getBookhoardUUID()
|
||||
@@ -699,9 +701,9 @@ function Bookhoard:collectBookData()
|
||||
end
|
||||
|
||||
function Bookhoard:collectAnnotations()
|
||||
local bookmarks = {}
|
||||
local highlights = {}
|
||||
local notes = {}
|
||||
local bookmarks = json_util.InitArray({})
|
||||
local highlights = json_util.InitArray({})
|
||||
local notes = json_util.InitArray({})
|
||||
|
||||
if not self.ui.bookmark then
|
||||
return bookmarks, highlights, notes
|
||||
|
||||
Reference in New Issue
Block a user