From fb7c32ca74f1bdd4a2864d238d4c7906b3690676 Mon Sep 17 00:00:00 2001 From: Robert Andrew Ditthardt Date: Sun, 19 Feb 2017 16:37:51 -0800 Subject: [PATCH] empty_as_json flag, 0.5-0 --- lusty-json-0.4-0.rockspec => lusty-json-0.5-0.rockspec | 6 +++--- lusty-json/output/json.lua | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) rename lusty-json-0.4-0.rockspec => lusty-json-0.5-0.rockspec (83%) diff --git a/lusty-json-0.4-0.rockspec b/lusty-json-0.5-0.rockspec similarity index 83% rename from lusty-json-0.4-0.rockspec rename to lusty-json-0.5-0.rockspec index 406d593..5e281dd 100644 --- a/lusty-json-0.4-0.rockspec +++ b/lusty-json-0.5-0.rockspec @@ -1,8 +1,8 @@ package = "lusty-json" -version = "0.4-0" +version = "0.5-0" source = { - url = "https://github.com/Olivine-Labs/lusty-json/archive/v0.4.tar.gz", - dir = "lusty-json-0.4" + url = "https://github.com/Olivine-Labs/lusty-json/archive/v0.5.tar.gz", + dir = "lusty-json-0.5" } description = { summary = "json input and output for lusty.", diff --git a/lusty-json/output/json.lua b/lusty-json/output/json.lua index 3a1bba1..a1371aa 100644 --- a/lusty-json/output/json.lua +++ b/lusty-json/output/json.lua @@ -3,6 +3,11 @@ local json = config.json return { handler = function(context) context.response.headers["content-type"] = "application/json" + if config.empty_as_array then + if type(context.output) == 'table' and next(context.output) == nil then + return context.response.send('[]') + end + end context.response.send(json.encode(context.output)) end,