I have a file with this content, where i am Parsing the file content as JSON:-
{
"OOH.wu.2023.9.53": {
"Brand": "***",
"Contract Number": "OOH.wu.2023.9.53",
"Client Name": "****",
"Sector": "FOODS",
"Media_list": [
{
"Network": "****",
"Amount": "4000.000",
"Duration": "1 Month",
"of_Faces": "1",
"Start_Date": "01-Oct-2023",
"End_Date": "01-Nov-2023",
"Delivery Date": "01-Oct-2023"
},
{
"Network": "****",
"Amount": "4800.000",
"Duration": "1 Month",
"of_Faces": "1",
"Start_Date": "01-Oct-2023",
"End_Date": "01-Nov-2023",
"Delivery Date": "01-Oct-2023"
},
{
"Network": "****",
"Amount": "4250.000",
"Duration": "1 Month",
"of_Faces": "1",
"Start_Date": "01-Oct-2023",
"End_Date": "01-Nov-2023",
"Delivery Date": "01-Oct-2023"
}
],
"No of Faces": "3"
},
"OOH.wu.2023.7.50": {
"Brand": "****",
"Contract Number": "OOH.wu.2023.7.50",
"Client Name": "****",
"Sector": "****",
"Media_list": [
{
"Network": "****",
"Amount": "4250.000",
"Duration": null,
"of_Faces": "1",
"Start_Date": "14-Aug-2023",
"End_Date": "14-Sep-2023",
"Delivery Date": "14-Aug-2023"
},
{
"Network": "****",
"Amount": "4250.000",
"Duration": null,
"of_Faces": "1",
"Start_Date": "09-Aug-2023",
"End_Date": "09-Sep-2023",
"Delivery Date": "09-Aug-2023"
}
],
"No of Faces": "2"
}
}
then i am trying to convert the JSON into an array, to be able to ApplyToEach item inside the json, so i followed this step:
xpath(xml(body('Parse_JSON')), '/root/*')
, as follow:-but i got this error:-
InvalidTemplate. Unable to process template language expressions in action 'Compose_2' inputs at line '0' and column '0': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Path 'outputs.body['OOH.wu.2023.9.53']'.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.
any advice? thanks
The error message clearly states what the error is. Unlike JSON, XML must have one single root element, where in your case the JSON has multiple root elements.
Try the following:
xpath(xml(concat('{"contracts":', string(body('Parse_JSON')), '}')), '/root/*')