function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sushma  RamakrishnanSushma Ramakrishnan 

Unexpected character ('T' (code 84)): was expecting comma to separate OBJECT entries at input location

Hi,

Please kindly help to resolve the above JSON Exception and also :
Unexpected character ('M' (code 77)): was expecting comma to separate OBJECT entries at input location.
Unexpected character ('P' (code 80)): was expecting comma to separate OBJECT entries at input location

All Help is Appreciated...!Thanks In advance...!
BalajiRanganathanBalajiRanganathan
You should escape quotes and backslash in your data before converting that as JSON.

For example {"name" : "VALUE \" has Quotes\" in it"}

\" Double quote
\\ Backslash caracter
 
Anupam RastogiAnupam Rastogi
Hi Sushma,

Share the JSON string pls

Thanks
AR
Sushma  RamakrishnanSushma Ramakrishnan
For Unexpected character ('P' (code 80)): was expecting comma to separate OBJECT entries at input location :

&

For Unexpected character ('T' (code 84)): was expecting comma to separate OBJECT entries at input location :

"description_maktx": ""PmpAcc,Cable,LMI,26034-20,20FTEXT""
BalajiRanganathanBalajiRanganathan
You are getting 
"description_maktx": ""PmpAcc,Cable,LMI,26034-20,20FTEXT""

but it should be 

"description_maktx": "\"PmpAcc,Cable,LMI,26034-20,20FTEXT\""


so you have to use \" for Double quote.

 
Anupam RastogiAnupam Rastogi

Hi Sushma,

Replace the two double quotes with single double quotes using the following method - 

String transformedText = ParserOutput.replace('""', '"');

Here ParserOutput is the string that contains the output to be transformed.

This should make the output as 

"description_maktx": "PmpAcc,Cable,LMI,26034-20,20FTEXT"

Thanks

If the reply solves your problem then please mark it as best answer.
Sushma  RamakrishnanSushma Ramakrishnan
Hi Anupam,

I have already tried this Solution as suggested by you :  finaloutput = finaloutput.replace('""','"');
It did solve some of my JSON parisng exceptions but not completely.

Hi Balaji,

If a escape the front double quotes by :  finaloutput = finaloutput.replace('""','"\"');
then how shall i replace it for the double quotes at the end of my String...?

Please help...
Also is JSON Encoding and Decoding possible in Apex...
I need some permanent solution to fix this issue...
 
BalajiRanganathanBalajiRanganathan
Are you generating the Json or Getting from external Service?. you need to ask the service provider to fix it as they are not giving you the valid JSON. that would be your permanent solution. bacially their JSON Generator is not escaping the double quotes.

Temporary (and not complete) fix would be
finaloutput = finaloutput.replaceAll('""','"\"');
 
@Amit Kumar Giri@Amit Kumar Giri
@BalajiRanganathan - Your this solution fixed my issue perfectly. 
finaloutput = finaloutput.replaceAll('""','"\"');