title: Extract specific info from json-list
body: <p>In my system from json-call <a href="http://192.168.1.6:8080/json.htm?type=devices&amp;rid=89" rel="nofollow noreferrer">http://192.168.1.6:8080/json.htm?type=devices&amp;rid=89</a> I get the output below.</p>
  
  <pre><code>{
     "ActTime" : 1501360852,
     "ServerTime" : "2017-07-29 22:40:52",
     "Sunrise" : "05:50",
     "Sunset" : "21:28",
     "result" : [
        {
           "AddjMulti" : 1.0,
           "AddjMulti2" : 1.0,
           "AddjValue" : 0.0,
           "AddjValue2" : 0.0,
           "BatteryLevel" : 255,
           "CustomImage" : 0,
           "Data" : "73 Lux",
           "Description" : "",
           "Favorite" : 1,
           "HardwareID" : 4,
           "HardwareName" : "Dummies",
           "HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
           "HardwareTypeVal" : 15,
           "HaveTimeout" : true,
           "ID" : "82089",
           "LastUpdate" : "2017-07-29 21:16:22",
           "Name" : "ESP8266C_Licht1",
           "Notifications" : "false",
           "PlanID" : "0",
           "PlanIDs" : [ 0 ],
           "Protected" : false,
           "ShowNotifications" : true,
           "SignalLevel" : "-",
           "SubType" : "Lux",
           "Timers" : "false",
           "Type" : "Lux",
           "TypeImg" : "lux",
           "Unit" : 1,
           "Used" : 1,
           "XOffset" : "0",
           "YOffset" : "0",
           "idx" : "89"
        }
     ],
     "status" : "OK",
     "title" : "Devices"
  }
  </code></pre>
  
  <p>'Automating' such call by the below scripttime lua-script is aimed at extraction of specific information, to be further used in applications.</p>
  
  <p>The first 11 lines run without problems, but further extraction of the information is a problem.</p>
  
  <p>I have tried various scriptlines to get a solution for A), B), C), D) and E), but either they generate error-report, or they don't give results: see further below for the 'best' trial-scriptlines and related results.</p>
  
  <p><em>To avoid misunderstanding</em>: those dashed commentlines in the script just below this question with A), B), C), D) and E) are only describing the desired actions/functions and are in <strong>no</strong> way meant as scriptlines!</p>
  
  <p><strong>Question:</strong></p>
  
  <p><em>Help requested in the form of better applicable scriptlines for A) till E) in the trialscript at the end of this message, or hints where to find applicable example scriptlines.</em></p>
  
  <pre><code>-- Lua-script to determine staleness, time-out and value for data from Json-call
  print('Start of Timeout-script')
  commandArray = {}
  TimeOutLimit = 10  -- Allowed timeout in seconds
  json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Linux
  --  json = (loadfile "D:\\Domoticz\\scripts\\lua\\json.lua")()  -- For Windows
  -- Line 07
     local content=assert(io.popen('curl "http://192.168.1.6:8080/json.htm?type=devices&amp;rid=89"')) -- notice double quotes
     local list = content:read('*all')
     content:close()
     local jsonList = json:decode(list)
  -- Line 12 Next scriptlines describe desired actions 
  -- A) Extract ServerTime as numeric value (not as string)
  -- B) Extract LastUpdate as numeric value (not as string)
  --  Staleness = ServerTime - LastUpdate
  -- C) Extract HaveTimeout as boolean (not as string)
  --  If HaveTimeout and (Staleness &gt; TimeOutlimit) then
  --       Print('TimeOutLimit exceeded by ' .. (Staleness - TimeOutLimit) .. 'seconds')
  --  End
  -- D) Extract textstring from Type or Data
  -- E) Extract numeric value from Data
  print('End of Timeout-script')
  return commandArray
  </code></pre>
  
  <p>For lines 11 etc, the following trial-scriptlines gave 'best' results (= no errors):</p>
  
  <pre><code>-- Line 11
  --       local Servertime = json:decode(ServerTime)
  --       print('Servertime   :  '..Servertime)
  -- Line 14
  --       CheckTimeOut =jsonValue.result[1].HaveTimeout -- value from "HaveTimeout", inside "result" bloc number 1 (even if it's the only one)
         CurrentServerTime =jsonValue.Servertime -- value from "ServerTime"
         CurrentLastUpdate = jsonValue.result[1].LastUpdate
         CurrentData = jsonValue.result[1].Data
  -- Line 19
         print('TimeOut      : '..CheckTimeOut)
         print('Servertime   : '..CurrentServerTime)
         print('LastUpdate   : '..CurrentLastUpdate)
         print('Data-content : '..CurrentData)
  print('End of Timeout-script')
  return commandArray
  </code></pre>
  
  <p><strong>Results:</strong></p>
  
  <p><em>Without</em> dashes before the lines 12 and 13, respectively 15, then the following error reports:</p>
  
  <pre><code>660: nil passed to JSON:decode()
  
  lua:15: attempt to index global 'jsonValue' (a nil value)
  </code></pre>
  
  <p><em>With</em> dashes before lines 12, 13 and 15 for the trial-scriptlines shown above, according to the log no errors exist (as demonstrated by the 2 prints)</p>
  
  <pre><code>2017-07-31 16:30:02.520 LUA: Start of Timeout-script
  2017-07-31 16:30:02.563 LUA: End of Timeout-script 
  </code></pre>
  
  <p>But why no print-results in the log from Lines 20 till 23?
  Not having those print-results makes it difficult to determine next steps in data-extraction, to achieve the objectives described under A) till E).</p>
  
  <p>;-) Error reports generally are more useful information than "no errors, but no results"</p>