{"id":1376,"date":"2026-02-03T04:11:19","date_gmt":"2026-02-03T04:11:19","guid":{"rendered":"https:\/\/monkey.ploogie.co.uk\/?page_id=1376"},"modified":"2026-02-03T04:11:19","modified_gmt":"2026-02-03T04:11:19","slug":"mwnci-loadjson-function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-loadjson-function\/","title":{"rendered":"Mwnci loadjson() Function"},"content":{"rendered":"<h2>Syntax<\/h2>\n<p>loadjson<strong>(<em>filename<\/em>)<\/strong><\/p>\n<h2>Description<\/h2>\n<p>The <i>loadjson()<\/i> function reads the JSON contents of a file and returns a usable data structure, such as an array or hash.<\/p>\n<h2>Example<\/h2>\n<p>File <em>myfile.json<\/em>:<\/p>\n<pre>\r\n{\r\n  \"cpu0\": {\r\n    \"user\": 0,\r\n    \"softirq\": 0,\r\n    \"guest_nice\": 0,\r\n    \"nice\": 0,\r\n    \"system\": 0,\r\n    \"idle\": 100,\r\n    \"steal\": 0,\r\n    \"guest\": 0,\r\n    \"iowait\": 0,\r\n    \"irq\": 0\r\n  },\r\n  \"cpu2\": {\r\n    \"guest\": 0,\r\n    \"iowait\": 0,\r\n    \"irq\": 0,\r\n    \"user\": 0,\r\n    \"system\": 0,\r\n    \"idle\": 100,\r\n    \"softirq\": 0,\r\n    \"guest_nice\": 0,\r\n    \"nice\": 0,\r\n    \"steal\": 0\r\n  }\r\n}\r\n<\/pre>\n<pre>include(\"json\")\r\nData=loadjson(\"myfile.json\")\r\nprintln(Data)\r\ncpu2Idle=Data[\"cpu2\"][\"idle\"]\r\nprintln(\"CPU2 is \", 100 - cpu2Idle, \"% busy\")\r\n\r\n\r\n{\"cpu2\": {\"irq\": 0, \"idle\": 100, \"guest_nice\": 0, \"steal\": 0, \"iowait\": 0, \"user\": 0, \"guest\": 0, \"softirq\": 0, \"nice\": 0, \"system\": 0}, \"cpu0\": {\"iowait\": 0, \"softirq\": 0, \"irq\": 0, \"guest_nice\": 0, \"nice\": 0, \"user\": 0, \"idle\": 100, \"guest\": 0, \"system\": 0, \"steal\": 0}}\r\nCPU2 is 0% busy\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Syntax loadjson(filename) Description The loadjson() function reads the JSON contents of a file and returns a usable data structure, such as an array or hash. Example File myfile.json: { &#8220;cpu0&#8221;: { &#8220;user&#8221;: 0, &#8220;softirq&#8221;: 0, &#8220;guest_nice&#8221;: 0, &#8220;nice&#8221;: 0, &#8220;system&#8221;: 0, &#8220;idle&#8221;: 100, &#8220;steal&#8221;: 0, &#8220;guest&#8221;: 0, &#8220;iowait&#8221;: 0, &#8220;irq&#8221;: 0 }, &#8220;cpu2&#8221;: { &#8220;guest&#8221;: &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-loadjson-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci loadjson() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1376","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1376"}],"version-history":[{"count":3,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1376\/revisions"}],"predecessor-version":[{"id":1379,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1376\/revisions\/1379"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}