title: Check if value exists in Lua table
body: <p>I am running Lua on ESP8266 Wifi module with NodeMCU firmware. My application is listening on TCP port for JSON requests. When I get the request I parse it using:</p>
  
  <pre><code>jsonRequest = json.decode(request)
  </code></pre>
  
  <p>So then I can access desired value with:</p>
  
  <pre><code>jsonRequest.object.state
  </code></pre>
  
  <p>Everything works perfectly until I send an invalid JSON (without "object"). When that happens I get this error: <strong><em>Lua API (attempt to index a nil value)</em></strong> and my program stops with execution.</p>
  
  <p>MY PROBLEM: I would like to check if my table contains that key before accessing, but I can't find a way to do it.</p>
  
  <p>I could do it with <strong><em>pairs</em></strong> function and loop through all keys and check if there is the right one, but that would require <strong>lots</strong> of code because I have multiple nested objects in my JSON.</p>
  
  <p>Any ideas?</p>