lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2017-04-15 0:18 GMT+02:00 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>> I used to like lua-cjson but it does not sit well with Lua 5.3.
>> Whenever a string could represent a number, it converts
>> it to a float, so that every integer prints with a .0 at the end.
>
> The version at https://github.com/mpx/lua-cjson does not seem to have this:
>
>         local json = require "cjson"
>         print(json.encode{1, 2.0, 3})
>
> prints
>         [1,2,3]
>
> (but I expected 2.0 here!)

I can only consider modules that are either in luarocks (so that my
user does not need building skills) or in pure lua with a license that
allows me to include the code in my own distribution. There seem to
be quite a few of both kinds.

Even roll-my-own is likely to be adequate for the actual data, which
is generated by some PHP server and seems to consist of a one-element
list containing associative arrays. My fallback if the user does not
have a json module I recognize is

function json_decode(s)
  return { load('return '..s:match'%b[]':sub(2,-2):
    gsub('("[%w_-]-"):','[%1]='))() }
end

So far it has not failed :-)