<p>The plugin probably uses PHP's <a href="http://php.net/manual/en/function.json-encode.php" rel="nofollow noreferrer"><code>json_encode</code></a> to serialize the data and it automatically escapes quotation marks and backslashes to conform to the <a href="http://json.org" rel="nofollow noreferrer">JSON format</a>. Escaping the <em>forward slashes</em> 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:</p>

<p><a href="https://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped">https://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped</a></p>

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

CC BY-SA 3.0
2016-01-29T12:44:47.717Z
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
Adam Menczykowski
CC BY-SA 3.0
2016-01-29T12:35:43.613Z
2016-01-29T12:52:22.570Z
2017-05-23T12:38:53.957Z
carlcs
<p>I am generating a url within Element API:</p>

<pre><code>'profile' =&gt; UrlHelper::getUrl("directory/company/{$member-&gt;id}/{$urlslug}"),
</code></pre>

<p>which outputs:</p>

<pre><code>http:\/\/craft.fira\/directory\/company\/1501\/abet-limited
</code></pre>

<p>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?</p>

<p>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.</p>

<p>Thanks in advance guys! :-)</p>

<plugin-elementapi><javascript><regex>
Element API - UrlHelper generates backwards slashes (regex)
# Element API - UrlHelper generates backwards slashes (regex)

(Asked by: username_0 on 2016-01-29)

I am generating a url within Element API:
'profile' => UrlHelper::getUrl("directory/company/{$member->id}/{$urlslug}"),

which outputs:
http:\/\/craft.fira\/directory\/company\/1501\/abet-limited

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! :-)

**Tags:** plugin-elementapi, javascript, regex


---

## 1 answers

### Answer by username_1 on 2016-01-29. Score: 2 | Accepted answer

The plugin probably uses PHP's [`json_encode`](http://php.net/manual/en/function.json-encode.php) to serialize the data and it automatically escapes quotation marks and backslashes to conform to the [JSON format](http://json.org). 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:

<https://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped>

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.

> **Comments:**
> **username_0**: 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  

---

