i have a file shown like below:
{
"status": "success",
"msg": {
"status": "success",
"inscount": 2,
"critical": 0,
"result": [
{
"Insulin": "Insuman Rapid",
"morning change": 0,
"noon change": 1,
"evening change": 0,
"action": 3,
"change morning from": "22",
"change noon from": "9",
"change evening from": "20",
"change morning to": "22",
"change noon to": "12",
"change evening to": "20",
"change type": "1"
},
{
"Insulin": "Insuman basal",
"morning change": 0,
"noon change": 0,
"evening change": 0,
"action": null,
"change morning from": "7",
"change noon from": "6",
"change evening from": "8",
"change morning to": "7",
"change noon to": "6",
"change evening to": "8",
"change type": “1”
}
],
"balance": "9974"
}
}
this is a JSON response from a web service and i am saving it into a temp. file. i want to extract the result array into a perl array of object.
it was generated with the following service call
system("curl -X POST -H '$CONTENT_TYPE' -d '$ARGS' -o $TEMP_FILE $SERVICE_URL 2>/dev/null");
I am using this code to extract the status, critical and inscount
if (open(OUTFILE,"<$TEMP_FILE")) {
while(<OUTFILE>) {
chomp;
if (/status\"?\:\s*\"success\"/) {
$SUCCESS=1;
print"Success File open********* Febin :) \n";
}
if (/critical\"?\:\s*\"1\"/) {
$CRITICAL=1;
}
if (/change type\"?\:\s*\"(\d+)\"/) {
$CHANGE_TYPE=$1;
}
if (/balance\"?\:\s*\"([^\"]+)\"/) {
$BALANCE=$1;
}
foreach $key (keys %TIME_VALUES) {
if(/$key\schange\"?\:\s*\"1\"/) {
$TIME_VALUES{$key}[0] = 1;
}
if(/change $key from\"?\:\s*\"([^\"]+)\"/) {
$TIME_VALUES{$key}[1] = $1;
}
if(/change $key to\"?\:\s*\"([^\"]+)\"/) {
$TIME_VALUES{$key}[2] = $1;
}
}
}
close(OUTFILE);
is there any way to do this please help
i am new to perl scripting