1

I am getting following JSON through AJAX call which is Invalid due to \t after bullet point, Due to this i am getting javaScript error in JSON.Parse(data.d) function. Could you please suggest how to handle this situation ?

{ "Initial" :[ 
                       {"IncidentNumber" : "INCB68686857575" ,
                       "IncidentStart": "22-Apr-2016 11:03" ,
                       "Title": "aaa", 
                       "ServiceName": "a",
                       "Status": "Service Down",
                       "UsersImpacted": "MULTIPLE" ,
                       "Circle": "a" ,
                       "RecoveryActivity": "•\tJohn Michel USA Country nextline•\tABC DEF GDH LMN	India" ,
                       "EstimatedRestorationTime": "a" ,
                       "OwningOrLeadTeam": "a" ,
                       "SupportingTeams": "a" ,
                       "IncidentLead": "a",
                       "Resiliency": "To Be Determined",
                       "NextUpdateGMTTime": "17-May-2016 12:48" }]
}

7
  • 3
    this runs fine in my console panel. What do you observe as error? Commented May 17, 2016 at 13:33
  • Possible duplicate of: stackoverflow.com/questions/4935632/parse-json-in-javascript Commented May 17, 2016 at 13:34
  • @RegisPortalez I am getting Invalid Character found and if i remove spacing between bullet point and ABC in 'Recovery Activity' then it works fine..But from back end instead of Spaced it is coming as '\t'. Commented May 17, 2016 at 13:37
  • Could you provide us with a snippet of the code you are using to parse the JSON ? if you would like to keep \t in the result you should probably escape the special character in the backend code Commented May 17, 2016 at 13:38
  • First thing is that this is already a valid json, there's no need to parse it. If it is in string form, then you can simply use JSON.parse to parse it ( not JSON.Parse ). Commented May 17, 2016 at 13:38

1 Answer 1

0

Use replace

var stringified = JSON.stringify(data);
JSON.parse(stringified.replace(/"/g,'"'));  
Sign up to request clarification or add additional context in comments.

2 Comments

I am getting error as 'JavaScript runtime error: Object doesn't support property or method 'replace' '
Updated my answer. You need to call replace on your json string object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.