Himanshu Pandey
Himanshu Pandey

Reputation: 708

Json is not validating with file content?

I have tested my json data with normal content that is working fine.

Sample data as below:

Working Json

 {
  "language": "XYZ",
  "content": {
    "GEN": "this is test",
    "EXO": "this is test"
   }
 }

Not working json

 {
  "language": "XYZ",
  "content": {
    "GEN": "\id GEN\n\c 1\n\p\n\v 1 In the beginning God created the heavens and the earth.\n\v 2 And the earth was without form and was void form.",
    "EXO": "\id EXO\n\c 1\n\p\n\v 1 Now these are the names of the children of Israel, which came to Egypt; every man and his household came with Jacob\n\v 2 Reuben, Simeon, Levi, and Judah"
   }
}

Check screenshot for working and not working json

Upvotes: 0

Views: 61

Answers (2)

Bharathi
Bharathi

Reputation: 1328

For the escape sequences, you can convert your object into JSON string and then parse like below this

 var obj= {
            "language": "XYZ",
            "content": {
                "GEN": "\id GEN\n\c 1\n\p\n\v 1 In the beginning God created the heavens and the earth.\n\v 2 And the earth was without form and was void form.",
                "EXO": "\id EXO\n\c 1\n\p\n\v 1 Now these are the names of the children of Israel, which came to Egypt; every man and his household came with Jacob\n\v 2 Reuben, Simeon, Levi, and Judah"
            }
        };
        var json= JSON.stringify(obj);

This will be more simple to you.

Upvotes: 0

deceze
deceze

Reputation: 522155

The only backslash escape sequences JSON permits are \b, \f, \n, \r, \t and \". All other uses of a backslash must be escaped as \\. The problem is that \i (and some of the other escape sequences) don't mean anything to JSON and are therefore a syntax error. Write it as \\i instead.

Upvotes: 1

Related Questions