use json_encode on variables nested in JS