Easiest Solution I found:
You can force json_encode to use actual numbers for values that look like numbers:
json_encode($data, JSON_NUMERIC_CHECK)
(since PHP 5.3.3).
Or you could just cast your ID to an int.
$row = $result->fetch_assoc();
$id = (int) $row['userid'];