Parse with PHP

This commit is contained in:
Tommy Huff 2016-10-25 18:55:23 -04:00
parent 4839953328
commit 56bbf3b05c
3 changed files with 147 additions and 108 deletions

20
advanced/Scripts/json.php Normal file
View file

@ -0,0 +1,20 @@
<?php
if ((isset($argv[1])) && (isset($argv[2]))) {
$json="$argv[1]";
$key="$argv[2]";
$result=json_decode($json, true);
if (is_array($result)) {
if (array_key_exists($key, $result)) {
echo "$result[$key]";
} else {
//key dosnt exist
die("Error KEY");
}
} else {
//invalid json
die("Error JSON");
}
} else {
die("Usage: php json.php \"JSON DATA HERE\" \"Key\"");
}
?>