JSON: Difference between revisions

Content added Content deleted
Line 2,525: Line 2,525:
print("JSON from new Lua data: " .. json.encode(data))</lang>
print("JSON from new Lua data: " .. json.encode(data))</lang>


Since in Lua <code>nil</code> signifies an ''undefined'' value, i.e. a variable or table entry with a <code>nil</code> value is undistinguishable from an undefined variable or non-existing table entry, a <code>null</code> value in JSON notation is decoded to a special function value, which ensures that it can be re-encoded properly to <code>null</code> again.
Since in Lua, a variable or table entry with <code>nil</code> is treated as the same as an undefined variable or non-existing table entry, a <code>null</code> value in JSON is decoded to a special function value, which ensures that it can be re-encoded properly to <code>null</code> again.
To manually insert a <code>null</code> value in the JSON output,
To manually insert a <code>null</code> value in the JSON output,
use the <code>json.util.null</code> function.
use the <code>json.util.null</code> function.