- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 02:29 AM
Trying below script but the JSON only prints [object object]. What is the mistake here.
if (gr.isValidRecord()) {
result.u_class = gr.u_env_class;
result.u_status = gr.install_status;
}
return JSON.stringify(result);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 02:32 AM
Hi Rupal,
gr.field_name returns the object. It's better to convert it to string while saving it in JSON.
if (gr.isValidRecord()) {
result.u_class = gr.u_env_class.toString();
result.u_status = gr.install_status.toString();
}
return JSON.stringify(result);
Please mark correct/helpful if applicable.
Regards,
Shubham
Shubham Tipnis
ServiceNow Enthusiast
⭐️ 3x Rising Star (2022–2024) – ServiceNow Community
Sharing insights, use cases & real-world learnings from the Now Platform
Always learning. Always building.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 02:32 AM
Hi Rupal,
gr.field_name returns the object. It's better to convert it to string while saving it in JSON.
if (gr.isValidRecord()) {
result.u_class = gr.u_env_class.toString();
result.u_status = gr.install_status.toString();
}
return JSON.stringify(result);
Please mark correct/helpful if applicable.
Regards,
Shubham
Shubham Tipnis
ServiceNow Enthusiast
⭐️ 3x Rising Star (2022–2024) – ServiceNow Community
Sharing insights, use cases & real-world learnings from the Now Platform
Always learning. Always building.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 02:28 AM
In my case - I had different scenario but the way you suggested to convert to string really worked well as my result printing as empty object {} though it has right value in it because it was in [Object Object] format and now without using for each loop I can get the object value and can print the JSON in format. I searched so many articles and found this perfect solution.
Thanks for your suggestion!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 02:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 02:51 AM
Hi,
Please convert that JSON object to string using -
JSON.stringify(json_object_name);