json validator in lua/openresty

609 views
Skip to first unread message

Samarjit Uppal

unread,
Sep 22, 2014, 10:27:31 AM9/22/14
to openre...@googlegroups.com

Does the openresty installation have any json validator for lua? the cjson.decode just blows up and the cjson library does not seem to have a validation method for json?

Do i have to use some other open source libs written for Lua for JSON validation? 

James Hurst

unread,
Sep 22, 2014, 10:58:06 AM9/22/14
to openre...@googlegroups.com
Hi,

cjson.decode will give you some hints in an error string if you call using pcall. If you just want to ensure it doesn't blow up at run time, pcall is definitely all you need: http://www.lua.org/manual/5.1/manual.html#pdf-pcall

local ok, res = pcall(cjson.decode, json)

'ok' will either be true of false, and 'res' will either be the return value or an error string.

James.


On 22 September 2014 15:27, Samarjit Uppal <uppal...@gmail.com> wrote:

Does the openresty installation have any json validator for lua? the cjson.decode just blows up and the cjson library does not seem to have a validation method for json?

Do i have to use some other open source libs written for Lua for JSON validation? 

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James Hurst

Samarjit Uppal

unread,
Sep 22, 2014, 12:44:14 PM9/22/14
to openre...@googlegroups.com

That was exactly what I needed. Thanks so much. :)

You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/zcZJySqb8UY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openresty-en...@googlegroups.com.

Swetha Kurup

unread,
May 31, 2019, 8:58:21 PM5/31/19
to openresty-en
Hi Samarjit, 

I am looking for a lua based json validator too. Would be great if you could post the sample code you got working. Thanks in advance,


On Monday, September 22, 2014 at 11:44:14 AM UTC-5, Samarjit Uppal wrote:

That was exactly what I needed. Thanks so much. :)

On 22-Sep-2014 8:28 pm, "James Hurst" <ja...@pintsized.co.uk> wrote:
Hi,

cjson.decode will give you some hints in an error string if you call using pcall. If you just want to ensure it doesn't blow up at run time, pcall is definitely all you need: http://www.lua.org/manual/5.1/manual.html#pdf-pcall

local ok, res = pcall(cjson.decode, json)

'ok' will either be true of false, and 'res' will either be the return value or an error string.

James.
On 22 September 2014 15:27, Samarjit Uppal <uppal...@gmail.com> wrote:

Does the openresty installation have any json validator for lua? the cjson.decode just blows up and the cjson library does not seem to have a validation method for json?

Do i have to use some other open source libs written for Lua for JSON validation? 

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openre...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
James Hurst

--
You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/zcZJySqb8UY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openre...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages