[vlc-devel] [PATCH 7/7] clean up json output by removing unnecessary array indicators

Rob Jonson rob at hobbyistsoftware.com
Tue Sep 27 11:45:33 CEST 2011


---
 share/lua/intf/modules/httprequests.lua |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index 3f513bb..f202b7c 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -196,9 +196,28 @@ function xmlString(s)
   end
 end
 
+--dkjson outputs numbered tables as arrays
+--so we don't need the array indicators
+function removeArrayIndicators(dict)
+	local newDict=dict
 
+	for k,v in pairs(dict) do
+		if (type(v)=="table") then
+			local arrayEntry=v._array
+			if arrayEntry then
+				v=arrayEntry
+			end
+
+			dict[k]=removeArrayIndicators(v)
+		end
+	end
+
+	return newDict
+end
 
 printTableAsJson = function (dict)
+	dict=removeArrayIndicators(dict)
+
 	local output=dkjson.encode (dict, { indent = true })
 	print(output)
 end
-- 
1.7.5




More information about the vlc-devel mailing list