Both codes work
but I am not able to replace :
$data = '{"success":true,"name":"winspiral","total":196864,"withdrawn":0,"balance":196864}';
by
$data='$file';
why?
Because :
1. If $file contains the JSON, it must be either just
$file (no quote, or double quote instead of single) or just use $file as the data.
2. If you want to read the data from a file, use something like
$data = file_get_contents($path_to_file) (or whatever is the API you get your JSON from)
Anyway, this is very basic programming. If you're planning to deal with other people money, you shouldn't do this yourself.