harningt / luajson

JSON parser/encoder for Lua Parses JSON using LPEG for speed and flexibility. Depending on parser/encoder options, various values are preserved as best as possible.
http://www.eharning.us/wiki/luajson/
Other
251 stars 48 forks source link

Customizing "null" #33

Closed mtdowling closed 10 years ago

mtdowling commented 10 years ago

The docs say that you can customize the value that the library uses to represent null values. I've been trying to figure out how this can be achieved, but I'm not having any luck.

Here's what I'm trying, however, this still returns a function to represent null values instead of nil.

> json_decoder = require('json').decode.getDecoder({null=nil})
> print(json_decoder('null'))
function: 0x7fc39ac1d290

Can you tell me how to change the value used to represent null values?

mtdowling commented 10 years ago

Ah, I found it:

local json_decoder = json.decode.getDecoder({
  others = {
    null = false
  }
})