From 1a79af583fd6170cb44ec8ee400acf0d1a4e0a8a Mon Sep 17 00:00:00 2001 From: Drew Ditthardt Date: Fri, 21 Mar 2014 11:48:25 -0700 Subject: [PATCH] Added config option for how to handle empty tables by default --- src/output/json.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/output/json.lua b/src/output/json.lua index 5b5f4a7..c87a29e 100644 --- a/src/output/json.lua +++ b/src/output/json.lua @@ -11,7 +11,14 @@ return { output = meta.__toView(output, context) end - context.response.send(json.encode(output)) + local raw + if config.encodeEmptyTableAsArray and next(output) == nil then + raw = "[]" + else + raw = json.encode(output) + end + + context.response.send(raw) end, options = {