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" }]
}
Pushkar Jaju
  • 569
  • 1
  • 4
  • 11
  • 3
    this runs fine in my console panel. What do you observe as error? – Regis Portalez May 17 '16 at 13:33
  • Possible duplicate of: http://stackoverflow.com/questions/4935632/parse-json-in-javascript – dane May 17 '16 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'. – Pushkar Jaju May 17 '16 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 – Vladimir Drenovski May 17 '16 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` ). – Mohit Bhardwaj May 17 '16 at 13:38
  • Possible duplicate of [How to remove " from my Json in javascript?](http://stackoverflow.com/questions/9244824/how-to-remove-quot-from-my-json-in-javascript) – layonez May 17 '16 at 13:43
  • @LayonezWronskey , Vladimir Drenovski , Regis Portalez i have updated my JSON, in above JSON I am getting problem with '\t'. – Pushkar Jaju May 17 '16 at 14:58

1 Answers1

0

Use replace

var stringified = JSON.stringify(data);
JSON.parse(stringified.replace(/"/g,'"'));  
layonez
  • 1,746
  • 1
  • 16
  • 20