Reputation: 119
Hi am trying to create a JSON Object but it shows error invalid characters found this is my JSON.
{
"title":"Biology",
"content":"Egg period: 4 -6 days \n
Eggs laid in cracks and crevices of the loose bark on the trunk \n
Eggs: ovoid or elliptical and dirty white in colour \n
Adult :Reddish brown in colour",
"isSubtitle":"N"
}
Please help to fix this and explain the cases of invalid characters in making JSON will be helpful.
Upvotes: 1
Views: 3936
Reputation: 804
This is an invalid JSON format , content shouldn't have line feed character so you should despecialize it to be \\n
.
So the valid format is :
{
"title": "Biology",
"content": "Egg period: 4 -6 days \\n Eggs laid in cracks and crevices of the loose bark on the trunk \\n Eggs: ovoid or elliptical and dirty white in colour \\n Adult: Reddish brown in colour ",
"isSubtitle": "N"
}
Upvotes: 2
Reputation: 2175
Line breaks in a JSON String must be escaped to \n
. JSON can take any-Unicode-character-except-"-or--or-control-character. Your JSON should look like this:
{
"title": "Biology",
"content": "Egg period: 4 -6 days \n Eggs laid in cracks and crevices of the loose bark on the trunk \n Eggs: ovoid or elliptical and dirty white in colour \n Adult :Reddish brown in colour",
"isSubtitle": "N"
}
Try to validate with jsonlint.com for the future.
Upvotes: 2