replaced json_encode with recursive array/object-literal encoding