From f8d14dc3b34ba452c5a737510c17ca1a89b039cb Mon Sep 17 00:00:00 2001 From: Lewis Marshall Date: Thu, 24 Apr 2014 02:05:32 +0100 Subject: [PATCH] controller: Render an empty JSON array when crud lists are empty Signed-off-by: Lewis Marshall --- crud.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crud.go b/crud.go index 7310911007..8d2af7267c 100644 --- a/crud.go +++ b/crud.go @@ -72,6 +72,10 @@ func crud(resource string, example interface{}, repo Repository, r martini.Route r.JSON(500, struct{}{}) return } + // render an empty JSON array (rather than null) if list is nil + if list == nil { + list = []struct{}{} + } r.JSON(200, list) })