JSON and Data Shapes
JSON Numbers
JSON numbers decode into numeric values that can be used in calculations.
JSON Numbers
json_numbers.php
<?php
$qty = ;
$json = '{"item":"pen","qty":' . $qty . '}';
$count = json_decode($json, true)["qty"];
$total = $count * 2;
echo "qty=" . $qty . "\n";
echo "total=" . $total . "\n";
<?php
$qty = ;
$json = '{"item":"pen","qty":' . $qty . '}';
$count = json_decode($json, true)["qty"];
$total = $count * 2;
echo "qty=" . $qty . "\n";
echo "total=" . $total . "\n";
<?php
$qty = ;
$json = '{"item":"pen","qty":' . $qty . '}';
$count = json_decode($json, true)["qty"];
$total = $count * 2;
echo "qty=" . $qty . "\n";
echo "total=" . $total . "\n";
numeric field
After decoding, calculate with the selected numeric field and print scalar results.