autodetection and solving json_encode issue