Add subentry to return json
This commit is contained in:
parent
dc527e93de
commit
ee7b2eeb75
|
@ -37,6 +37,7 @@ pub fn main() !void {
|
|||
;
|
||||
|
||||
var jobj = json.Obj.newFromString(jsonText);
|
||||
defer jobj.deinit();
|
||||
|
||||
try request.process(&jobj, &db);
|
||||
}
|
||||
|
|
|
@ -11,17 +11,23 @@ pub fn process(jobj: *json.Obj, db: *sqlite.Db) !void {
|
|||
defer arena.deinit();
|
||||
const allocator = arena.allocator();
|
||||
|
||||
var jret = json.Obj.newObject();
|
||||
defer jret.deinit();
|
||||
|
||||
// Test the action to carry and pass the object
|
||||
if (jobj.objectGet("add") catch null) |*jadd| {
|
||||
try add(jadd, db, allocator);
|
||||
var ret = try add(jadd, db, allocator);
|
||||
jret.objectAdd("added", &ret);
|
||||
}
|
||||
|
||||
std.debug.print("{s}", .{ jret.toString() });
|
||||
}
|
||||
|
||||
pub fn add(jobj: *json.Obj, db: *sqlite.Db, allocator: std.mem.Allocator) !void {
|
||||
pub fn add(jobj: *json.Obj, db: *sqlite.Db, allocator: std.mem.Allocator) !json.Obj {
|
||||
// TODO: Maybe return error when no items in the array?
|
||||
|
||||
// Freed by the caller
|
||||
var jret = json.Obj.newArray();
|
||||
defer jret.deinit();
|
||||
|
||||
var iter = jobj.arrayGetIterator();
|
||||
while(iter.next()) |*jtags| {
|
||||
|
@ -38,5 +44,5 @@ pub fn add(jobj: *json.Obj, db: *sqlite.Db, allocator: std.mem.Allocator) !void
|
|||
jret.arrayAdd(&item.toJson());
|
||||
}
|
||||
|
||||
std.debug.print("{s}", .{ jret.toString() });
|
||||
return jret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue