- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 09:55 AM - edited 07-29-2024 09:57 AM
HI Team,
Below is sample code which is written in After Business Rule. I believe the issue is from line no 35 to line no 38 is not printing anything. I believe XML to JSON conversion is the issue.
In my try catch block I am getting error as "Unexpected Token o".
Attached is the sample code in notepad .If you see the catch block I am getting error as Unexpected Token o
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 01:05 AM
Hi @Ankur Khare
please make the below changes:
// Parse JSON string back to an object
var objHandle = JSON.parse(jsonString);
gs.log('objHandle: ' + JSON.stringify(objHandle)); // Log objHandle for debugging
// Access and log specific properties
if (objHandle.net) {
gs.log('parentNetHandle: ' + objHandle.net.parentNetHandle);
} else {
gs.log('The "net" property does not exist in the JSON object.');
}
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 10:23 AM
There's likely some character coming through in the XML that's tanking the JSON Parser. Print out the XML and look at it, you may need to replace some of the characters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 10:36 AM
Hi @Ankur Khare
The error message Unexpected Token o typically occurs when JSON.parse is called on an object instead of a JSON string.
Can you try replacing code from line 35 with the below code:
var jsonObj = gs.xmlToJSON(responseBody);
gs.log('JSON Object: ' + JSON.stringify(jsonObj));
var jsonString = JSON.stringify(jsonObj);
// Parse JSON String into a JSON object
var objHandle = JSON.parse(jsonString);
gs.log('Parent Net Handle: ' + objHandle.parentNetHandle);
……………………………………………………………………………………………………
Please Mark it helpful 👍and Accept Solution✔️!! If this helps you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 12:55 AM
@Satishkumar B After making the above change,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 01:05 AM
Hi @Ankur Khare
please make the below changes:
// Parse JSON string back to an object
var objHandle = JSON.parse(jsonString);
gs.log('objHandle: ' + JSON.stringify(objHandle)); // Log objHandle for debugging
// Access and log specific properties
if (objHandle.net) {
gs.log('parentNetHandle: ' + objHandle.net.parentNetHandle);
} else {
gs.log('The "net" property does not exist in the JSON object.');
}
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................