I am generating a url within Element API:

'profile' => UrlHelper::getUrl("directory/company/{$member->id}/{$urlslug}"),

which outputs:


What do I need to do to turn this into a real url without the backwards slashes "\"? As far as I understand this is a regular expression (regex) version of the url?

I will be using javascript to put this on the page, so it could either be fixed at source in the Element api php code, or alternatively when scraping through the JSON with Javascript.

Thanks in advance guys! :-)

1 Answer 1


The plugin probably uses PHP's json_encode to serialize the data and it automatically escapes quotation marks and backslashes to conform to the JSON format. Escaping the forward slashes of your URL wouldn't actually be necessary, but I just found this on StackOverflow which might give an idea why the function escapes them anyways:


But you shouldn't really care about this behavior at all, because however you gonna consume that JSON string, the parser (e.g., jQuery.parseJSON()) should handle the unescaping for you.

  • Great. Sorry - newb questions... So I won't need to alter what is being output now anyway, all should run smoothly by the sounds of things. Thank you so much for your help Commented Jan 29, 2016 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.