Array & string in rest message

shalani r
Tera Contributor

Hi all,

     Can anyone please tell me on how to convert this into exact output as shown in image:

shalanir_0-1702386297149.png

 

shalanir_4-1702386568903.png

after split its not separated as double quotes with comma its working as M-23AL,M-35HM

so kindly request to help with this.

 

Thanks in advance!

 

10 REPLIES 10

Stefan Georgiev
Tera Guru

Hello @shalani r ,

I am not sure what you are trying to do here, but in the second picture you are showing a JSON and in the first picture this.org is a string type, have you tried to JSON.parse() or JSON.stringify(), depending on what your final goal is.


Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful and Accepting the Solution so other community users can find it faster.

All the Best,
Stefan

Hello @Stefan Georgiev ,

     Thanks for your response.

1st image is the script which i'm using and 2nd image is the expected result.

FYI.

 

Regards,

Shalani R

Hello @shalani r,
yes after the split(',') you need to JSON.stringify() it, but if you want the same result as in the second picture you need to 

var orgArr = allOrg.split(',')

var objToJSON = {organizations: orgArr }
var jsonObj = JSON.stringify(objToJSON )

gs.info(jsonObj)

But I am not sure what is your final goal and why you need it, you want to reuse some REST message logic you have or something?
Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful and Accepting the Solution so other community users can find it faster.

All the Best,
Stefan

Thanks for your response.

I wanted the same result as shown in second image but it should be of array format.

 

Thanks in advance!