I have a document as below.
let j = {
"PolicyInfo" :
{
"id" : "12345",
"PolNum" : "TestPolicy",
"NameInfo":
{
"idref":"9999",
"Name":"TestName"
}
}
}
My requirement is to convert id (under PolicyInfo) and also idref (under NameInfo) to attributes while converting to XML. I am able to use below code to handle one attribute.
const JsonConfig = json.config('custom');
JsonConfig['whitespace'] = 'ignore';
JsonConfig['attribute-names'] = 'id';
json.transformFromJson(j, JsonConfig)
I tried below options but both of them not working.
JsonConfig['attribute-names'] = ['id','idref'];
JsonConfig['attribute-names'] = ('id','idref');
Is there a way to handle multiple attributes while converting to XML?
Thanks in advance!
Yes, use the Sequence.from
function:
JsonConfig['attribute-names'] = Sequence.from(['id', 'idref']);