Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T12:44:47.717Z
Answers.Text: 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
Answers.UserDisplayName: Adam Menczykowski
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T12:35:43.613Z
Answers.LastActivityDate: 2016-01-29T12:52:22.570Z
Answers.LastEditDate: 2017-05-23T12:38:53.957Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <plugin-elementapi><javascript><regex>
Title: Element API - UrlHelper generates backwards slashes (regex)
ThreadText: # 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  
  
  ---
  
  