Help to transform just one property of array object into string

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 10:56 AM
Hello guys,
I need help to transform just one property of array object into string. How can I achieve this?
var obj = [{
"name": "John",
"board_order": 1,
},
{
"name": "Paul",
"board_order": 2,
}];
//To this:
var obj = [{
"name": "John",
"board_order": "1",
},
{
"name": "Paul",
"board_order": "2",
}];
Thanks in advance.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 11:12 AM
Hi,
Try this -
const myJSON = JSON.stringify(obj);
gs.info(myJSON+ "\n\n");
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 11:28 AM
Hi,
Unfortunately it didn't work!
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 11:39 AM
Hi
Try this
var obj = [{
"name": "John",
"board_order": 1,
},
{
"name": "Paul",
"board_order": 2,
}];
for(var i=0; i<obj.length; i++){
obj[i].board_order = obj[i].board_order.toString();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 03:17 PM
This works for me. You could try it on Scripts - Background ( All menu > System Definition > Scripts - Background)