# Help with json response

**URL:** <https://forum.ionicframework.com/t/help-with-json-response/52638>\
**Category:** ionic-v1\
**Created:** [May 21, 2016, 5:18pm UTC](https://forum.ionicframework.com/t/help-with-json-response/52638 "2016-05-21T17:18:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [May 21, 2016, 5:18pm UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/1 "2016-05-21T17:18:21Z")

</div>

Hello guys

```
               `i am making a web service call and the returned json contains \\n instead \n so how can i convert \\n to \n in angularjs`
```

---

<div class="post-metadata">

**Author:** ![Destroy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/destroy/32/94194_2.png) [@Destroy](https://forum.ionicframework.com/u/Destroy)\
**Post date:** [May 21, 2016, 5:28pm UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/2 "2016-05-21T17:28:56Z")

</div>

Try with something like this:

`var response = {'key': '\\n test\\n some test\\n new test'}; var newchar = '\\n'; var oldchar = '\n'; var replacedResponse = JSON.parse(JSON.stringify(response).split(',').join(newchar));`

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [May 21, 2016, 5:43pm UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/3 "2016-05-21T17:43:00Z")

</div>

thanks buddy will try it and let you know

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [May 21, 2016, 5:51pm UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/4 "2016-05-21T17:51:37Z")

</div>

this approach is not working

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [May 21, 2016, 6:03pm UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/5 "2016-05-21T18:03:34Z")

</div>

```
          {"Title":"Haramukk","Date":"2016-05-04 00:00:00","Description":"Lyath wuchkha maen \\n hehra lazmaya maaji hendis guudis","User":"Ezaz","Place":"Srinagar","id":0,"Category":"Pyul","author":"Ezaz"}

     this is the console.log of the data i am receiving i want to convert \\n to \n in Description key 

```

@Destroy

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 21, 2016, 10:34pm UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/6 "2016-05-21T22:34:34Z")

</div>

I must be missing something here, but why do you feel the need to do this? `\\n` is what newlines look like in JSON, and `JSON.parse` should convert them into newlines in the resulting object properties. This shouldn’t be something you have to concern yourself with in application code.

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [May 22, 2016, 5:49am UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/7 "2016-05-22T05:49:14Z")

</div>

i tried JSON.parse in the application code and browser

in browser it seems to be working while as in application code doesnt work

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [May 22, 2016, 5:50am UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/8 "2016-05-22T05:50:25Z")

</div>

```
 var text = {"Title":"Haramukk","Date":"2016-05-04 00:00:00","Description":"Lyath wuchkha maen \\n hehra lazmaya maaji hendis guudis","User":"Ezaz","Place":"Srinagar","id":0,"Category":"Pyul","author":"Ezaz"};

  obj = JSON.parse(JSON.stringify(text));
  console.log(obj);

```

This code works in browser but not in the application

---

<div class="post-metadata">

**Author:** ![ezazwar](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezazwar](https://forum.ionicframework.com/u/ezazwar)\
**Post date:** [May 22, 2016, 6:55am UTC](https://forum.ionicframework.com/t/help-with-json-response/52638/9 "2016-05-22T06:55:17Z")

</div>

@mhartington can you help me in this matter

i just want to add a filter to description key so that i can break it into paragraphs but this doesnt seem to be working

It works in browser but not in ionic app

```
JSON.parse(JSON.stringify(text)); 

 .filter('nl2p', function () {
return function(text){
    text = String(text).trim();
    return (text.length > 0 ? '<p>' + text.replace(/[\r\n]+/g, '</p><p>') + '</p>' : null);
}
}) 

```

Thanks
