-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_json.lua
More file actions
70 lines (47 loc) · 1.15 KB
/
import_json.lua
File metadata and controls
70 lines (47 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
importer.import_json_item=function(self, box, item)
local keyname, valuename, notesname, updatedname, key, value, notes, updated
if self.fields ~= nil
then
keyname=self.fields["key"]
valuename=self.fields["value"]
notesname=self.fields["notes"]
updatedname=self.fields["updated"]
else
keyname="name"
valuename="value"
notesname="notes"
updatedname="updated"
end
key=item:value(keyname)
value=item:value(valuename)
notes=item:value(notesname)
updated=item:value(updatedname)
if strutil.strlen(key) > 0
then
box:add(key, value, notes, updated)
self.items_imported=self.items_imported + 1
end
end
importer.import_json_list=function(self, box, items)
local item
item=items:next()
while item ~= nil
do
self:import_json_iterate(box, item)
item=items:next()
end
end
importer.import_json_iterate=function(self, box, item)
if item == nil then return end
if item:type() == "array"
then
items=parent:subitems()
self:import_json_list(box, items)
else self:import_json_item(box, item)
end
end
importer.import_json=function(self, box, doc)
local P, items, item
items=dataparser.PARSER("json", doc)
if items ~= nil then self:import_json_list(box, items) end
end