Skip to main content

NULL constant in JSON (json.null)

Declaration

json.null

Notes

This is not a function, but a constant. When printed as text it appears like "userdata: 0x0".
It represents the JSON null value.
Why is it necessary? Because nil in a Lua table means absence; when encoding to JSON, a key with nil disappears. A specific sentinel is needed to represent JSON null.
This value can be used in XUI.

Example

local tb = json.decode('{"nullvalue":null}')
if tb['nullvalue'] == json.null then
sys.alert(json.null)
end

Note: Uses sys.alert