AnsweredAssumed Answered

How to add JSON tags in an JSON array

Question asked by EYIndia on May 18, 2018
Latest reply on May 22, 2018 by EYIndia

Hi All,

 

I am using API gateway 9.2.I need to add the JSON tag in all arrays and value should be unique in each array and send it in response.Below is my policy ,used Run Assertion for each time to get the JSON array response.But in response need to append 3 more tags in each array with unique value.Tried by using add XML element assertion but i am unable to add the XML element in all elements(value should be unique in each element).

 

Note : In the below sample response ,EWB ,date and valid are the added JSON tags.In that EWB value should be unique number.

 

Request you to please help on the above query.

 

Payload in setcontext variable and hardcoded parameters which is not the actual requirement

${formattedResponse}
{
docno:${docno.results[0]},
doctype:${doctype.results[0]},
docDate: ${docdate.results[0]},
"EWB":"1234567",
"date":"11/05/2018"
"valid":"11/06/2018"
}

 

Sample request Payload 

{
"invoices": [{
"supplyType": "O",
"subSupplyType": "1",
"subSupplyDesc": "",
"docType": "INV",
"docNo": "123-8",
"docDate": "15/12/2017"

},
{
"supplyType": "O",
"subSupplyType": "1",
"subSupplyDesc": "",
"docType": "INV",
"docNo": "123-8",
"docDate": "15/12/2017"

},
{
"supplyType": "O",
"subSupplyType": "1",
"subSupplyDesc": "",
"docType": "INV",
"docNo": "123-8",
"docDate": "15/12/2017"

}
]
}

 

Getting Response:

{
docno:123-8,
doctype:INV,
docDate: 15/12/2017,
"EWB":"1234567",
"date":"11/05/2018"
"valid":"11/06/2018"
}
{
docno:123-8,
doctype:INV,
docDate: 15/12/2017,
"EWB":"1234567",
"date":"11/05/2018"
"valid":"11/06/2018"
}
{
docno:123-8,
doctype:INV,
docDate: 15/12/2017,
"EWB":"1234567",
"date":"11/05/2018"
"valid":"11/06/2018"
}

 

Expected Response :

 

{
docno:123-8,
doctype:INV,
docDate: 15/12/2017,
"EWB":"any unique number",
"date":"11/05/2018"
"valid":"11/06/2018"
}
{
docno:123-8,
doctype:INV,
docDate: 15/12/2017,
"EWB":"any unique number",
"date":"11/05/2018"
"valid":"11/06/2018"
}
{
docno:123-8,
doctype:INV,
docDate: 15/12/2017,
"EWB":"any unique number",
"date":"11/05/2018"
"valid":"11/06/2018"
}

 

 

Thanks & regards,

Ansar

Outcomes