I am trying to insert newline between strings in json,but didnt work.Here is the code
{ id: 0, address: "First line\r\nsecond line" },
Asked
Active
Viewed 710 times
-1

shamon shamsudeen
- 5,466
- 17
- 64
- 129
-
Check [this](http://stackoverflow.com/questions/11591784/parsing-json-containing-new-line-characters) – Deepak Biswal Oct 16 '14 at 10:05
-
1this is painfullly less amount of information. please elaborate what you mean when you say didn't work.. you can validate your json here http://jsonlint.org – UncleKing Oct 16 '14 at 10:06
-
Stop saying "didn't work". That tells us nothing at all. JSON Lint _does_ "work" so you did something wrong, and you've given us no information to determine what that something is. – Lightness Races in Orbit Oct 16 '14 at 10:10
-
@UncleKing return the console error `Parse error on line 2: [ { id: 0, name: --------------^ Expecting 'STRING', '}'` – shamon shamsudeen Oct 16 '14 at 10:17
-
jsonlint throws error for your string -- did you considering the adding quotes to your keys ? { "id": 0, "address": "First line\r\nsecond line" } ... still there is no information on your environment and what you mean by error or how youare trying to give this input to chrome – UncleKing Oct 16 '14 at 10:23
2 Answers
0
Your example works fine when the JSON is parsed and printed. It just doesn't appear as an actual newline when viewed as an Object.
var a = { id: 0, address: "First line\r\nsecond line" }
-> Object {id: 0, address: "First line↵second line"}
console.log(a.address)
-> First line
second line
Here's an example: http://jsfiddle.net/2wyfwoum/1/

Jivings
- 22,834
- 6
- 60
- 101
0
Finally i solved the problem using ng-bind-html
in angular js.Here is my update code
{ id: 0, address: "First line<br>second line" }
in my html <p ng-bind-html="friends.address"></p>
Result:
First line
second line

shamon shamsudeen
- 5,466
- 17
- 64
- 129