Skip to content
Snippets Groups Projects
Select Git revision
  • 4405f39869071ebd28fe5e9988a745534d6b3461
  • v2018.2.x default protected
  • 0x4A6F-rpi4
  • 0x4A6F-master
  • master
  • v2018.2.2-ffs
  • v2016.2.4-batmanbug
  • radv-filterd
  • v2016.2.x
  • hoodselector
  • v2016.1.x
  • babel
  • v2015.1.x
  • 2014.4.x
  • 2014.3.x
  • v2018.2.2-ffs0.1
  • v2018.2.1-ffs0.1
  • v2018.2.1
  • v2018.2-ffs0.1
  • v2018.2
  • v2018.1.4
  • v2018.1.3
  • v2018.1.2
  • v2018.1.1
  • v2018.1
  • v2017.1.8
  • v2017.1.7
  • v2017.1.6
  • v2017.1.5
  • v2017.1.4
  • v2017.1.3
  • v2017.1.2
  • v2016.2.7
  • v2017.1.1
  • v2017.1
35 results

0004-luci-lib-json-ignore-null-keys-to-allow-encoding-empty-objects.patch

Blame
  • Forked from firmware / FFS Gluon
    Source project has a limited visibility.
    0004-luci-lib-json-ignore-null-keys-to-allow-encoding-empty-objects.patch 1.17 KiB
    From: Matthias Schiffer <mschiffer@universe-factory.net>
    Date: Thu, 4 Jun 2015 21:03:24 +0200
    Subject: luci-lib-json: ignore null keys to allow encoding empty objects
    
    There is currently no way to encode an empty object {}, as empty tables are
    encoded as empty lists [].
    
    With this patch, encode() will ignore table fields with the key json.null (which
    doesn't make sense anyways). This allows adding a field with key json.null to
    force encoding it as an object.
    
    Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
    
    diff --git a/libs/luci-lib-json/luasrc/json.lua b/libs/luci-lib-json/luasrc/json.lua
    index 416b25f..f7b57f9 100644
    --- a/libs/luci-lib-json/luasrc/json.lua
    +++ b/libs/luci-lib-json/luasrc/json.lua
    @@ -149,11 +149,13 @@ function Encoder.parse_iter(self, obj)
     		local first = true
     
     		for key, entry in pairs(obj) do
    -			first = first or self:put(",")
    -			first = first and false
    -			self:parse_string(tostring(key))
    -			self:put(":")
    -			self:dispatch(entry)
    +			if key ~= null then
    +				first = first or self:put(",")
    +				first = first and false
    +				self:parse_string(tostring(key))
    +				self:put(":")
    +				self:dispatch(entry)
    +			end
     		end
     
     		self:put("}")