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:
{
"cpu0": {
"user": 0,
"softirq": 0,
"guest_nice": 0,
"nice": 0,
"system": 0,
"idle": 100,
"steal": 0,
"guest": 0,
"iowait": 0,
"irq": 0
},
"cpu2": {
"guest": 0,
"iowait": 0,
"irq": 0,
"user": 0,
"system": 0,
"idle": 100,
"softirq": 0,
"guest_nice": 0,
"nice": 0,
"steal": 0
}
}
include("json")
Data=loadjson("myfile.json")
println(Data)
cpu2Idle=Data["cpu2"]["idle"]
println("CPU2 is ", 100 - cpu2Idle, "% busy")
{"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}}
CPU2 is 0% busy