json building help required

rajasekahr
Tera Guru

i want to sent one json payload from service now

 

{
"projectId": "ba080779-242d-432a-828f-8d442b7dbac7",
"inputs": {
"jsonInput": "{variables of catalog task}"
},
"bulkRequestCount": 1
}

 

I am trying by below way using the strings,after getting the variables using the variable...please suggest best approach

 

var extravar=('{'+'\r\n'+'"'+"projectId"+'"'+':'+'"'+'ba080779-242d-432a-828f-8d442b7dbac7'+'"'+',\r\n'+'"'+"inputs"+'"'+':'+ '{\r\n'+'"'+"jsonInput"+'"'+':'+'"');

 

 gs.info(extravar+j.encode(output)+'"'+'\r\n'+'}'+',\r\n'+'"'+"bulkRequestCount"+'"'+':'+1+'\r\n'+'}');

 

2 REPLIES 2

Anand Kumar P
Giga Patron
Giga Patron

Hi @rajasekahr ,

 

Use stringify method for payload 

var jsonExtravar = JSON.stringify(extravar);

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

SN_Learn
Kilo Patron
Kilo Patron

Hi @rajasekahr ,

 

Please check the below article, it will provide you insights:

JSON PARSING: USE CASE AND SOLUTIONS 

JSON Encoding 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.