I want to transform the below source to target using XSLT, but unable to do so. Could you please help on it?
Source :
{
"gp_number" : "56826526",
"lineLevel" : [ {
"Qty" : "4.00",
"Rate" : "50.00"
}, {
"Qty" : "3.00",
"Rate" : "25.00"
} ]
}
Target:
{
"gp_number" : "56826526",
"AmountCal_line" : [ {
"Qty" : "4.00",
"Rate" : "50.00",
"Amount" : "200.00"
}, {
"Qty" : "3.00",
"Rate" : "25.00",
"Amount" : "75.00"
} ],
"TotalAmount" : "275.00"
}
With XSLT 3, as supported by current versions of SaxonJS (2.6 is the current version) or Saxon Java, SaxonC, Saxon .NET or SaxonCS, you can process JSON input (on the command line with option
-json) and produce JSON output (with XDM maps and arrays being serialized with output method json):Example fiddle using SaxonJS 2.