Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua cjson testing for null

Tags:

lua

I am using cjson to decode the following JSON. I want to test for the case that the items parameter is null. I am having difficulty finding a conditional to match this case. It's weird because it seems like it is not a string, not nil, but stil has a truthy value.

{
  "kind": "ServiceList",
  "apiVersion": "v1",
  "metadata": {
    "selfLink": "/api/v1/services",
    "resourceVersion": "47316"
  },
  "items": null
}

Here are the conditionals that I have tried:

if jsonServices.items == "null" then

if jsonServices.items == null then

if not jsonServices.items then

if jsonServices.items == nil

like image 280
frankgreco Avatar asked Oct 12 '25 09:10

frankgreco


1 Answers

found this in the Lua docs

if jsonServices.items == cjson.null then

works great!

like image 69
frankgreco Avatar answered Oct 14 '25 10:10

frankgreco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!