JSON Format disappearing on transfer to import set using import set REST API

nishtha3
Kilo Contributor

Hi,

We are using REST API to send data from Point a to b(servicenow target table).

we are using Import set web service for validations. So basically getting data in JSON format from source a and sending it to the import set using REST API wherein we will use transform map to map data to the target table.

SO, for sending data, In the REST API we are setting the endpoints(to import set), httpmethod(POST), authentication and the setting the body with the JSON string(received from source a).

Like:

var str = {"u_data":{"Company":"XYZ","Location":"ABC"}} // JSON string received from source a

request.setRequestBody(str); //sending to import set

But  I'm receiving this data in the import set table field(u_data) in the below format:

Company=XYZ,Location=ABC

so basically the data I'm receiving changes colon to equal sign and I'm not able to parse or stringify this data as it is not in valid JSON Format.

has anyone worked on a similar thing who could help me to get the data in JSON format in import set field or help me to convert the string to JSON.

Thanks

nisha

5 REPLIES 5

dvp
Mega Sage
Mega Sage

You need to pass the data value as string

Can you replace

var str = {"u_data":{"Company":"XYZ","Location":"ABC"}} // JSON string received from source a

with

var str = {"u_data":'{"Company":"XYZ","Location":"ABC"}'} // JSON string received from source a

 

 

Sanjay Bagri1
Tera Guru
Hi, If you want to parse the json data then you can use it . For parse the json object.. You can go once these links might be helpful for you https://community.servicenow.com/community?id=community_question&sys_id=f8b88361db5cdbc01dcaf3231f9619a2 I think below link is meeting your requirements: https://community.servicenow.com/community?id=community_question&sys_id=65fe3229db58dbc01dcaf3231f9619b6 var responseBody = '{"DomainName":"199.91.140.12","RegistryData":{"AbuseContact":{"Email":"abuse@service-now.com"}}}'; var obj = JSON.parse(responseBody); gs.print(obj.DomainName); . If it is helpful for you . Please mark as correct and also helpful. Becouse other also will benefited this answer. Thanks Sanjay Bagri

atul kumar1
Tera Contributor

Hi Nishtha,

 

You can create a business rule on the import set table and write below script.

 

var initialJsonFormat=current.yourfieldname;
var massagingStageValue=initialJsonFormat.replace(/=/g,':');
current.yourfieldname=massagingStageValue;
current.update();

Please mark correct. if it helps you.

 

Regards,

 

Atul

nishtha3
Kilo Contributor

Hello everyone,

 

Using toSring() on the incoming payload changed it to string and then we could parse the data and send.

var str = {"u_data":{"Company":"XYZ","Location":"ABC"}} // JSON string received from source a

var strg  = str.toString();

 

Nisha