I want to flatten data from a xbasic object (json). Cannot seems to get it right. Please see my Xbasic below and the result;
dim json as c
json ="orderField": [
{
"orderIdentificationField": {
"entityIdentificationField": "4981132656",
"contentOwnerField": null,
"PropertyChanged": null
},
"orderTypeCodeField": {
"codeListVersionField": "Normal",
"valueField": "220",
"PropertyChanged": null
},
"isApplicationReceiptAcknowledgementRequiredField": false,
"isApplicationReceiptAcknowledgementRequiredFieldSpecified": false,
"orderInstructionCodeField": null,
"additionalOrderInstructionField": {
"languageCodeField": null,
"codeListVersionField": null,
"valueField": "",
"PropertyChanged": null
},
"isOrderFreeOfExciseTaxDutyField": false,
"isOrderFreeOfExciseTaxDutyFieldSpecified": false,
"totalMonetaryAmountExcludingTaxesField": null,
"totalMonetaryAmountIncludingTaxesField": null,
"totalTaxAmountField": null,
"noteField": null,
"buyerField": {
"glnField": "6001001530705",
"additionalPartyIdentificationField": [
{
"additionalPartyIdentificationTypeCodeField": "BUYER_ASSIGNED_IDENTIFIER_FOR_A_PARTY",
"codeListVersionField": null,
"valueField": "53079",
"PropertyChanged": null
},
{
"additionalPartyIdentificationTypeCodeField": "BUYER_ASSIGNED_DESCRIPTION_FOR_A_PARTY",
"codeListVersionField": null,
"valueField": "SHOPRITE RUNDU",
"PropertyChanged": null
}
]
dim template as c
template = <<%str%
{
"orderIdentificationField": {
"entityIdentificationField": "OrderNo"},
"orderTypeCodeField": {
"codeListVersionField": "OrderType"},
"buyerField": {
"glnField": "shopGLN"}
}
%str%
dim json2 as c
json2 = json_flatten(json,template)
json2 = json_reformat(json2)
Result: for json2
[ { "OrderNo" : "8305065640" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001647106" }
, { "OrderNo" : "4985122130" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001404105" }
, { "OrderNo" : "9194009110" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009111" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009112" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009114" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "4985122194" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001404105" }
, { "OrderNo" : "9194009106" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009109" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009122" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "4991155189" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155190" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155192" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155193" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155194" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "7891050873" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7891050876" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7891050877" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7891050878" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7906043458" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383905" }
]
dim json as c
json ="orderField": [
{
"orderIdentificationField": {
"entityIdentificationField": "4981132656",
"contentOwnerField": null,
"PropertyChanged": null
},
"orderTypeCodeField": {
"codeListVersionField": "Normal",
"valueField": "220",
"PropertyChanged": null
},
"isApplicationReceiptAcknowledgementRequiredField": false,
"isApplicationReceiptAcknowledgementRequiredFieldSpecified": false,
"orderInstructionCodeField": null,
"additionalOrderInstructionField": {
"languageCodeField": null,
"codeListVersionField": null,
"valueField": "",
"PropertyChanged": null
},
"isOrderFreeOfExciseTaxDutyField": false,
"isOrderFreeOfExciseTaxDutyFieldSpecified": false,
"totalMonetaryAmountExcludingTaxesField": null,
"totalMonetaryAmountIncludingTaxesField": null,
"totalTaxAmountField": null,
"noteField": null,
"buyerField": {
"glnField": "6001001530705",
"additionalPartyIdentificationField": [
{
"additionalPartyIdentificationTypeCodeField": "BUYER_ASSIGNED_IDENTIFIER_FOR_A_PARTY",
"codeListVersionField": null,
"valueField": "53079",
"PropertyChanged": null
},
{
"additionalPartyIdentificationTypeCodeField": "BUYER_ASSIGNED_DESCRIPTION_FOR_A_PARTY",
"codeListVersionField": null,
"valueField": "SHOPRITE RUNDU",
"PropertyChanged": null
}
]
dim template as c
template = <<%str%
{
"orderIdentificationField": {
"entityIdentificationField": "OrderNo"},
"orderTypeCodeField": {
"codeListVersionField": "OrderType"},
"buyerField": {
"glnField": "shopGLN"}
}
%str%
dim json2 as c
json2 = json_flatten(json,template)
json2 = json_reformat(json2)
Result: for json2
[ { "OrderNo" : "8305065640" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001647106" }
, { "OrderNo" : "4985122130" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001404105" }
, { "OrderNo" : "9194009110" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009111" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009112" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009114" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "4985122194" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001404105" }
, { "OrderNo" : "9194009106" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009109" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "9194009122" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001828109" }
, { "OrderNo" : "4991155189" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155190" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155192" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155193" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "4991155194" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001010603" }
, { "OrderNo" : "7891050873" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7891050876" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7891050877" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7891050878" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383004" }
, { "OrderNo" : "7906043458" }
, { "OrderType" : "Normal" }
, { "shopGLN" : "6001001383905" }
]