Which JSON parser with 5.3?

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Which JSON parser with 5.3?

Dirk Laurie-2
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.

Any recommendations for a module that works under Lua 5.3
and does not have this annoying feature?

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Sean Conner
It was thus said that the Great Dirk Laurie once stated:
> 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.
>
> Any recommendations for a module that works under Lua 5.3
> and does not have this annoying feature?

  Are you asking for a JSON module, or anything that can
serialize/deserialize data between two spots, say like CBOR? [1][2]

  Another question:  what should the result be of:

        { "count" : 9223372036854775808 }

  -spc (It's an integer ... )

[1] http://cbor.io

[2] https://github.com/spc476/CBOR

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Luiz Henrique de Figueiredo
In reply to this post by Dirk Laurie-2
> 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!)

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Dirk Laurie-2
In reply to this post by Sean Conner
2017-04-14 22:42 GMT+02:00 Sean Conner <[hidden email]>:

> It was thus said that the Great Dirk Laurie once stated:
>> 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.
>>
>> Any recommendations for a module that works under Lua 5.3
>> and does not have this annoying feature?
>
>   Are you asking for a JSON module, or anything that can
> serialize/deserialize data between two spots, say like CBOR? [1][2]
>
>   Another question:  what should the result be of:
>
>         { "count" : 9223372036854775808 }
>
>   -spc (It's an integer ... )

In my application,

(a) I actually only need decoding into a Lua table
(b) integers will be within signed 32-bit range but I don't want floats for
them, so I'm not answering your trick question.

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Dirk Laurie-2
In reply to this post by Luiz Henrique de Figueiredo
2017-04-15 0:18 GMT+02:00 Luiz Henrique de Figueiredo <[hidden email]>:

>> 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 :-)

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Marc Balmer
In reply to this post by Dirk Laurie-2


Am 14.04.17 um 22:25 schrieb Dirk Laurie:
> 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.
>
> Any recommendations for a module that works under Lua 5.3
> and does not have this annoying feature?
>

We use our own for all JSON needs.  It is reasonably fast and is well
maintained:  gtihub.com/arcapos/luajson

- mb

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

云风 Cloud Wu
In reply to this post by Dirk Laurie-2


Dirk Laurie <[hidden email]>于2017年4月15日周六 上午5:45写道:
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.

Any recommendations for a module that works under Lua 5.3
and does not have this annoying feature?


You can use my fork :  https://github.com/cloudwu/lua-cjson

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Xpol Wan
There is my binding to rapidjson: https://github.com/xpol/lua-rapidjson
Or just luarocks install rapidjson

云风 Cloud Wu <[hidden email]>于2017年4月15日 周六下午4:40写道:


Dirk Laurie <[hidden email]>于2017年4月15日周六 上午5:45写道:
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.

Any recommendations for a module that works under Lua 5.3
and does not have this annoying feature?


Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Dirk Laurie-2
Thanks, this one satisfies the conditions. Unfortunately, it is
too strict for the JSON produced by the webpage. Example:
   [{"items":[];"date": "2017-04-15"}]
produces
   nil    Missing a comma or '}' after an object member. (12)
I'm not a JSON expert, so can't comment on the validity of the
original string, but I have no control over the webpage that
produces it.

In the meantlime, by Murphy's Law, the PHP page has thrown up
an nested list, so the fallback decoder is now:

 function json_decode (s)
    local function do_json_list(s,is_list)
      if is_list then s = s:sub(2,-2) end
      s = s:gsub("(%b[])()",do_json_list)
      if is_list then s = '{' .. s ..'}' end
      return s
    end
    local t = load('return '..do_json_list(s):gsub('("[%w_-]-"):','[%1]='))
    if t then return t() else return s end
  end

2017-04-15 14:51 GMT+02:00 Xpol Wan <[hidden email]>:

> There is my binding to rapidjson: https://github.com/xpol/lua-rapidjson
> Or just luarocks install rapidjson
>
> 云风 Cloud Wu <[hidden email]>于2017年4月15日 周六下午4:40写道:
>>
>>
>>
>> Dirk Laurie <[hidden email]>于2017年4月15日周六 上午5:45写道:
>>>
>>> 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.
>>>
>>> Any recommendations for a module that works under Lua 5.3
>>> and does not have this annoying feature?
>>>
>>
>> You can use my fork :  https://github.com/cloudwu/lua-cjson
>>
>> My pull request : https://github.com/mpx/lua-cjson/pull/22

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Charles Heywood
Semicolons (;) are not a part of the JSON specification.

On Sat, Apr 15, 2017, 09:21 Dirk Laurie <[hidden email]> wrote:
Thanks, this one satisfies the conditions. Unfortunately, it is
too strict for the JSON produced by the webpage. Example:
   [{"items":[];"date": "2017-04-15"}]
produces
   nil    Missing a comma or '}' after an object member. (12)
I'm not a JSON expert, so can't comment on the validity of the
original string, but I have no control over the webpage that
produces it.

In the meantlime, by Murphy's Law, the PHP page has thrown up
an nested list, so the fallback decoder is now:

 function json_decode (s)
    local function do_json_list(s,is_list)
      if is_list then s = s:sub(2,-2) end
      s = s:gsub("(%b[])()",do_json_list)
      if is_list then s = '{' .. s ..'}' end
      return s
    end
    local t = load('return '..do_json_list(s):gsub('("[%w_-]-"):','[%1]='))
    if t then return t() else return s end
  end

2017-04-15 14:51 GMT+02:00 Xpol Wan <[hidden email]>:
> There is my binding to rapidjson: https://github.com/xpol/lua-rapidjson
> Or just luarocks install rapidjson
>
> 云风 Cloud Wu <[hidden email]>于2017年4月15日 周六下午4:40写道:
>>
>>
>>
>> Dirk Laurie <[hidden email]>于2017年4月15日周六 上午5:45写道:
>>>
>>> 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.
>>>
>>> Any recommendations for a module that works under Lua 5.3
>>> and does not have this annoying feature?
>>>
>>
>> You can use my fork :  https://github.com/cloudwu/lua-cjson
>>
>> My pull request : https://github.com/mpx/lua-cjson/pull/22

--
--

Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Marc Balmer
In reply to this post by Marc Balmer


Am 15.04.17 um 09:00 schrieb Marc Balmer:

>
>
> Am 14.04.17 um 22:25 schrieb Dirk Laurie:
>> 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.
>>
>> Any recommendations for a module that works under Lua 5.3
>> and does not have this annoying feature?
>>
>
> We use our own for all JSON needs.  It is reasonably fast and is well
> maintained:  gtihub.com/arcapos/luajson

s/gtihub/github/, of course....

>
> - mb
>

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Dirk Laurie-2
In reply to this post by Charles Heywood
Probably my fault, retyping instead of cutting-and-pasting, and
having a Lua mindset. The JSON emitted by the page does have
commas.

2017-04-15 17:07 GMT+02:00 Charles Heywood <[hidden email]>:

> Semicolons (;) are not a part of the JSON specification.
>
>
> On Sat, Apr 15, 2017, 09:21 Dirk Laurie <[hidden email]> wrote:
>>
>> Thanks, this one satisfies the conditions. Unfortunately, it is
>> too strict for the JSON produced by the webpage. Example:
>>    [{"items":[];"date": "2017-04-15"}]
>> produces
>>    nil    Missing a comma or '}' after an object member. (12)
>> I'm not a JSON expert, so can't comment on the validity of the
>> original string, but I have no control over the webpage that
>> produces it.
>>
>> In the meantlime, by Murphy's Law, the PHP page has thrown up
>> an nested list, so the fallback decoder is now:
>>
>>  function json_decode (s)
>>     local function do_json_list(s,is_list)
>>       if is_list then s = s:sub(2,-2) end
>>       s = s:gsub("(%b[])()",do_json_list)
>>       if is_list then s = '{' .. s ..'}' end
>>       return s
>>     end
>>     local t = load('return
>> '..do_json_list(s):gsub('("[%w_-]-"):','[%1]='))
>>     if t then return t() else return s end
>>   end
>>
>> 2017-04-15 14:51 GMT+02:00 Xpol Wan <[hidden email]>:
>> > There is my binding to rapidjson: https://github.com/xpol/lua-rapidjson
>> > Or just luarocks install rapidjson
>> >
>> > 云风 Cloud Wu <[hidden email]>于2017年4月15日 周六下午4:40写道:
>> >>
>> >>
>> >>
>> >> Dirk Laurie <[hidden email]>于2017年4月15日周六 上午5:45写道:
>> >>>
>> >>> 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.
>> >>>
>> >>> Any recommendations for a module that works under Lua 5.3
>> >>> and does not have this annoying feature?
>> >>>
>> >>
>> >> You can use my fork :  https://github.com/cloudwu/lua-cjson
>> >>
>> >> My pull request : https://github.com/mpx/lua-cjson/pull/22
>>
> --
> --
>
> Ryan <[hidden email]>
> Software Developer / System Administrator
> https://hashbang.sh

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Sean Conner
In reply to this post by Dirk Laurie-2
It was thus said that the Great Dirk Laurie once stated:
> 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.
>
> Any recommendations for a module that works under Lua 5.3
> and does not have this annoying feature?

  I've just released my own JSON parser [1] that can return integers that
runs under Lua 5.1 or greater.  The only dependency is LPeg.  It is
available for downloading via LuaRocks with the module name
"org.conman.parsers.json".  The code was pretty much lifted straight off the
json.org homepage.

  -spc

[1] https://github.com/spc476/LPeg-Parsers/blob/master/json.lua


Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Eric Wing
Just curious, how well does dkjson work with 5.3? I recall it has a
pure Lua backend and a LPeg backend.

Thanks,
Eric

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Russell Haley
On Mon, Apr 17, 2017 at 4:08 PM, Eric Wing <[hidden email]> wrote:
> Just curious, how well does dkjson work with 5.3? I recall it has a
> pure Lua backend and a LPeg backend.
>
> Thanks,
> Eric
>
I've had good success with dkjson in 5.3 but don't have time to test
against the requirements set out. It sure is fast...

Reply | Threaded
Open this post in threaded view
|

Re: Which JSON parser with 5.3?

Francisco Olarte
In reply to this post by Eric Wing
On Tue, Apr 18, 2017 at 1:08 AM, Eric Wing <[hidden email]> wrote:
> Just curious, how well does dkjson work with 5.3? I recall it has a
> pure Lua backend and a LPeg backend.

We use it for all our work, pure Lua one, but our docs are not
complex, difficult or big.

Francisco Olarte.