davidcalhoun / jstoxml

JavaScript object to XML converter (useful for RSS, podcasts, GPX, AMP, etc)
MIT License
178 stars 23 forks source link

Not working properly for Arrays #71

Closed baharalidurrani closed 1 year ago

baharalidurrani commented 1 year ago

I'm trying to convert the following JSON to XML. But it can’t parse arrays correctly. Here's a current versus desired result: https://gist.github.com/baharalidurrani/6ae5951337488ae8659c04da144a67ad/revisions

Screenshot 2023-01-18 at 16 48 03

If we look at the screenshot above we can clearly see that we lost some tags on line numbers 29,30 and 41,42.

{
  "MESSAGE": {
    "ABOUT_VERSIONS": {
      "ABOUT_VERSION": [
        {
          "CreatedDatetime": "2019-02-22T14:24:17Z"
        }
      ]
    },
    "DEAL_SETS": {
      "DEAL_SET": [
        {
          "DEALS": {
            "DEAL": [
              {
                "ASSETS": {
                  "ASSET": [
                    {
                      "ASSET_DETAIL": {
                        "AssetAccountIdentifier": 123456,
                        "AssetCashOrMarketValueAmount": 12000,
                        "AssetType": "CheckingAccount"
                      },
                      "ASSET_HOLDER": {
                        "NAME": {
                          "FullName": "Bank of Noosh"
                        }
                      }
                    },
                    {
                      "ASSET_DETAIL": {
                        "AssetAccountIdentifier": 1234567,
                        "AssetCashOrMarketValueAmount": 100000,
                        "AssetType": "CertificateOfDepositTimeDeposit"
                      },
                      "ASSET_HOLDER": {
                        "NAME": {
                          "FullName": "Bank of Noosh"
                        }
                      }
                    },
                    {
                      "ASSET_DETAIL": {
                        "AssetAccountIdentifier": 6465456,
                        "AssetCashOrMarketValueAmount": 50000,
                        "AssetType": "TrustAccount",
                        "FundsSourceType": "Other",
                        "FundsSourceTypeOtherDescription": "Trust"
                      },
                      "ASSET_HOLDER": {
                        "NAME": {
                          "FullName": "Fidelity Investments"
                        }
                      }
                    },
                    {
                      "ASSET_DETAIL": {
                        "AssetAccountIdentifier": 55555,
                        "AssetCashOrMarketValueAmount": 120000,
                        "AssetType": "MutualFund"
                      },
                      "ASSET_HOLDER": {
                        "NAME": {
                          "FullName": "UBS"
                        }
                      }
                    }
                  ]
                },
                "COLLATERALS": {
                  "COLLATERAL": [
                    {
                      "SUBJECT_PROPERTY": {
                        "ADDRESS": {
                          "AddressLineText": "10655 Birch St",
                          "CityName": "Burbank",
                          "PostalCode": "915021234",
                          "StateCode": "CA"
                        },
                        "PROPERTY_DETAIL": {
                          "AttachmentType": "Attached",
                          "CommunityPropertyStateIndicator": true,
                          "ConstructionMethodType": "SiteBuilt",
                          "FinancedUnitCount": 1,
                          "PropertyEstateType": "FeeSimple",
                          "PropertyExistingCleanEnergyLienIndicator": false,
                          "PropertyInProjectIndicator": false,
                          "PropertyMixedUsageIndicator": false,
                          "PropertyStructureBuiltYear": 1965,
                          "PropertyUsageType": "PrimaryResidence",
                          "PUDIndicator": false
                        },
                        "PROPERTY_VALUATIONS": {
                          "PROPERTY_VALUATION": {
                            "PROPERTY_VALUATION_DETAIL": {
                              "PropertyValuationAmount": 340000
                            }
                          }
                        },
                        "SALES_CONTRACTS": {
                          "SALES_CONTRACT": {
                            "SALES_CONCESSIONS": {
                              "SALES_CONCESSION": {
                                "SalesConcessionAmount": 1000
                              }
                            },
                            "SALES_CONTRACT_DETAIL": {
                              "SalesContractAmount": 340000
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "LIABILITIES": {
                  "LIABILITY": [
                    {
                      "LIABILITY_DETAIL": {
                        "LiabilityAccountIdentifier": 98,
                        "LiabilityExclusionIndicator": false,
                        "LiabilityMonthlyPaymentAmount": 44,
                        "LiabilityPayoffStatusIndicator": false,
                        "LiabilityRemainingTermMonthsCount": 10,
                        "LiabilityType": "Revolving",
                        "LiabilityUnpaidBalanceAmount": 437
                      },
                      "LIABILITY_HOLDER": {
                        "NAME": {
                          "FullName": "HEMLOCKS"
                        }
                      }
                    },
                    {
                      "LIABILITY_DETAIL": {
                        "LiabilityAccountIdentifier": "291443C81189",
                        "LiabilityExclusionIndicator": false,
                        "LiabilityMonthlyPaymentAmount": 425,
                        "LiabilityPayoffStatusIndicator": false,
                        "LiabilityRemainingTermMonthsCount": 35,
                        "LiabilityType": "Installment",
                        "LiabilityUnpaidBalanceAmount": 14748
                      },
                      "LIABILITY_HOLDER": {
                        "NAME": {
                          "FullName": "HILLSIDE BANK"
                        }
                      }
                    }
                  ]
                },
                "LOANS": {
                  "LOAN": [
                    {
                      "AMORTIZATION": {
                        "AMORTIZATION_RULE": {
                          "AmortizationType": "Fixed",
                          "LoanAmortizationPeriodCount": 360,
                          "LoanAmortizationPeriodType": "Month"
                        }
                      },
                      "CLOSING_INFORMATION": {
                        "CLOSING_ADJUSTMENT_ITEMS": {
                          "CLOSING_ADJUSTMENT_ITEM": {
                            "CLOSING_ADJUSTMENT_ITEM_DETAIL": {
                              "ClosingAdjustmentItemAmount": 1000,
                              "ClosingAdjustmentItemType": "LenderCredit"
                            }
                          }
                        },
                        "CLOSING_INFORMATION_DETAIL": {
                          "CashFromBorrowerAtClosingAmount": 28800
                        }
                      },
                      "DOCUMENT_SPECIFIC_DATA_SETS": {
                        "DOCUMENT_SPECIFIC_DATA_SET": {
                          "URLA": {
                            "URLA_DETAIL": {
                              "ApplicationSignedByLoanOriginatorDate": "2019-01-07",
                              "EstimatedClosingCostsAmount": 6000,
                              "PrepaidItemsEstimatedAmount": 2750
                            },
                            "URLA_TOTAL": {
                              "EXTENSION": {
                                "OTHER": {
                                  "URLA_TOTAL_EXTENSION": {
                                    "URLATotalSellerCreditsAmount": 4750
                                  }
                                }
                              }
                            }
                          }
                        }
                      },
                      "HMDA_LOAN": {
                        "HMDA_LOAN_DETAIL": {
                          "HMDA_HOEPALoanStatusIndicator": false
                        }
                      },
                      "HOUSING_EXPENSES": {
                        "HOUSING_EXPENSE": [
                          {
                            "HousingExpensePaymentAmount": 1475.82,
                            "HousingExpenseTimingType": "Proposed",
                            "HousingExpenseType": "FirstMortgagePrincipalAndInterest"
                          },
                          {
                            "HousingExpensePaymentAmount": 50,
                            "HousingExpenseTimingType": "Proposed",
                            "HousingExpenseType": "MIPremium"
                          },
                          {
                            "HousingExpensePaymentAmount": 75,
                            "HousingExpenseTimingType": "Proposed",
                            "HousingExpenseType": "HomeownersInsurance"
                          },
                          {
                            "HousingExpensePaymentAmount": 165,
                            "HousingExpenseTimingType": "Proposed",
                            "HousingExpenseType": "RealEstateTax"
                          },
                          {
                            "HousingExpensePaymentAmount": 365,
                            "HousingExpenseTimingType": "Proposed",
                            "HousingExpenseType": "HomeownersAssociationDuesAndCondominiumFees"
                          },
                          {
                            "HousingExpensePaymentAmount": 100,
                            "HousingExpenseTimingType": "Proposed",
                            "HousingExpenseType": "Other"
                          }
                        ]
                      },
                      "LOAN_DETAIL": {
                        "ApplicationReceivedDate": "2019-01-06",
                        "BalloonIndicator": false,
                        "BelowMarketSubordinateFinancingIndicator": false,
                        "BorrowerCount": 1,
                        "BuydownTemporarySubsidyFundingIndicator": false,
                        "ConstructionLoanIndicator": false,
                        "InterestOnlyIndicator": false,
                        "NegativeAmortizationIndicator": false,
                        "PrepaymentPenaltyIndicator": false
                      },
                      "LOAN_IDENTIFIERS": {
                        "LOAN_IDENTIFIER": [
                          {
                            "LoanIdentifier": "DI-C01_v3.4",
                            "LoanIdentifierType": "LenderLoan"
                          }
                        ]
                      },
                      "PURCHASE_CREDITS": {
                        "PURCHASE_CREDIT": [
                          {
                            "PurchaseCreditAmount": 10000,
                            "PurchaseCreditType": "EarnestMoney"
                          },
                          {
                            "PurchaseCreditAmount": 4200,
                            "PurchaseCreditType": "LeasePurchaseFund"
                          }
                        ]
                      },
                      "TERMS_OF_LOAN": {
                        "BaseLoanAmount": 300000,
                        "LienPriorityType": "FirstLien",
                        "LoanPurposeType": "Purchase",
                        "MortgageType": "Conventional",
                        "NoteRatePercent": 4.25
                      }
                    }
                  ]
                },
                "PARTIES": {
                  "PARTY": [
                    {
                      "INDIVIDUAL": {
                        "CONTACT_POINTS": {
                          "CONTACT_POINT": [
                            {
                              "CONTACT_POINT_EMAIL": {
                                "ContactPointEmailValue": "ken.c@fanniemae.com"
                              }
                            },
                            {
                              "CONTACT_POINT_TELEPHONE": {
                                "ContactPointTelephoneValue": "8182222222"
                              }
                            },
                            {
                              "CONTACT_POINT_DETAIL": {
                                "ContactPointRoleType": "Home"
                              }
                            }
                          ]
                        },
                        "NAME": {
                          "FirstName": "Ken",
                          "LastName": "Customer",
                          "MiddleName": "N",
                          "SuffixName": "JR"
                        }
                      },
                      "ADDRESSES": {
                        "ADDRESS": {
                          "AddressLineText": "10655 Birch St",
                          "AddressType": "Mailing",
                          "CityName": "Burbank",
                          "CountryCode": "US",
                          "PostalCode": 915021234,
                          "StateCode": "CA"
                        }
                      },
                      "LANGUAGES": {
                        "LANGUAGE": {
                          "LanguageCode": "eng",
                          "EXTENSION": {
                            "OTHER": {
                              "LANGUAGE_EXTENSION": {
                                "LanguageRefusalIndicator": false
                              }
                            }
                          }
                        }
                      },
                      "ROLES": {
                        "ROLE": [
                          {
                            "BORROWER": {
                              "BORROWER_DETAIL": {
                                "BorrowerBirthDate": "1966-07-04",
                                "BorrowerTotalMortgagedPropertiesCount": 1,
                                "CommunityPropertyStateResidentIndicator": true,
                                "DependentCount": 0,
                                "DomesticRelationshipIndicator": true,
                                "DomesticRelationshipType": "DomesticPartnership",
                                "MaritalStatusType": "Unmarried"
                              },
                              "COUNSELING": {
                                "COUNSELING_EVENTS": {
                                  "COUNSELING_EVENT": [
                                    {
                                      "COUNSELING_EVENT_DETAIL": {
                                        "CounselingConfirmationIndicator": false,
                                        "CounselingType": "Counseling"
                                      }
                                    },
                                    {
                                      "COUNSELING_EVENT_DETAIL": {
                                        "CounselingConfirmationIndicator": false,
                                        "CounselingType": "Education"
                                      }
                                    }
                                  ]
                                }
                              },
                              "CURRENT_INCOME": {
                                "CURRENT_INCOME_ITEMS": {
                                  "CURRENT_INCOME_ITEM": [
                                    {
                                      "CURRENT_INCOME_ITEM_DETAIL": {
                                        "CurrentIncomeMonthlyTotalAmount": 10000,
                                        "EmploymentIncomeIndicator": true,
                                        "IncomeType": "Base"
                                      }
                                    },
                                    {
                                      "CURRENT_INCOME_ITEM_DETAIL": {
                                        "CurrentIncomeMonthlyTotalAmount": 1000,
                                        "EmploymentIncomeIndicator": true,
                                        "IncomeType": "Overtime"
                                      }
                                    },
                                    {
                                      "CURRENT_INCOME_ITEM_DETAIL": {
                                        "CurrentIncomeMonthlyTotalAmount": 750,
                                        "EmploymentIncomeIndicator": true,
                                        "IncomeType": "Bonus"
                                      }
                                    },
                                    {
                                      "CURRENT_INCOME_ITEM_DETAIL": {
                                        "CurrentIncomeMonthlyTotalAmount": 1000,
                                        "EmploymentIncomeIndicator": false,
                                        "IncomeType": "DividendsInterest"
                                      }
                                    },
                                    {
                                      "CURRENT_INCOME_ITEM_DETAIL": {
                                        "CurrentIncomeMonthlyTotalAmount": 100,
                                        "EmploymentIncomeIndicator": false,
                                        "IncomeType": "AutomobileAllowance"
                                      }
                                    },
                                    {
                                      "CURRENT_INCOME_ITEM_DETAIL": {
                                        "CurrentIncomeMonthlyTotalAmount": 250,
                                        "EmploymentIncomeIndicator": false,
                                        "IncomeType": "NotesReceivableInstallment"
                                      }
                                    },
                                    {
                                      "CURRENT_INCOME_ITEM_DETAIL": {
                                        "CurrentIncomeMonthlyTotalAmount": 1000,
                                        "EmploymentIncomeIndicator": false,
                                        "IncomeType": "Trust"
                                      }
                                    }
                                  ]
                                }
                              },
                              "DECLARATION": {
                                "DECLARATION_DETAIL": {
                                  "BankruptcyIndicator": false,
                                  "CitizenshipResidencyType": "USCitizen",
                                  "HomeownerPastThreeYearsType": "No",
                                  "IntentToOccupyType": "Yes",
                                  "OutstandingJudgmentsIndicator": false,
                                  "PartyToLawsuitIndicator": false,
                                  "PresentlyDelinquentIndicator": false,
                                  "PriorPropertyDeedInLieuConveyedIndicator": false,
                                  "PriorPropertyForeclosureCompletedIndicator": false,
                                  "PriorPropertyShortSaleCompletedIndicator": false,
                                  "PropertyProposedCleanEnergyLienIndicator": false,
                                  "UndisclosedBorrowedFundsIndicator": false,
                                  "UndisclosedComakerOfNoteIndicator": false,
                                  "UndisclosedCreditApplicationIndicator": false,
                                  "UndisclosedMortgageApplicationIndicator": false,
                                  "EXTENSION": {
                                    "OTHER": {
                                      "DECLARATION_DETAIL_EXTENSION": {
                                        "SpecialBorrowerSellerRelationshipIndicator": false
                                      }
                                    }
                                  }
                                }
                              },
                              "EMPLOYERS": {
                                "EMPLOYER": {
                                  "LEGAL_ENTITY": {
                                    "CONTACTS": {
                                      "CONTACT": {
                                        "CONTACT_POINTS": {
                                          "CONTACT_POINT": {
                                            "CONTACT_POINT_TELEPHONE": {
                                              "ContactPointTelephoneValue": 8183323332
                                            }
                                          }
                                        }
                                      }
                                    },
                                    "LEGAL_ENTITY_DETAIL": {
                                      "FullName": "National Consulting"
                                    }
                                  },
                                  "ADDRESS": {
                                    "AddressLineText": "1236 Main St",
                                    "CityName": "Burbank",
                                    "PostalCode": 915021234,
                                    "StateCode": "CA"
                                  },
                                  "EMPLOYMENT": {
                                    "EmploymentBorrowerSelfEmployedIndicator": false,
                                    "EmploymentClassificationType": "Primary",
                                    "EmploymentPositionDescription": "Consultant",
                                    "EmploymentStartDate": "2003-02-15",
                                    "EmploymentStatusType": "Current",
                                    "EmploymentTimeInLineOfWorkMonthsCount": 252,
                                    "SpecialBorrowerEmployerRelationshipIndicator": false,
                                    "EXTENSION": {
                                      "OTHER": {
                                        "EMPLOYMENT_EXTENSION": {
                                          "ForeignIncomeIndicator": false,
                                          "SeasonalIncomeIndicator": false
                                        }
                                      }
                                    }
                                  }
                                }
                              },
                              "GOVERNMENT_MONITORING": {
                                "GOVERNMENT_MONITORING_DETAIL": {
                                  "HMDAEthnicityRefusalIndicator": false,
                                  "HMDAGenderRefusalIndicator": false,
                                  "HMDARaceRefusalIndicator": false,
                                  "EXTENSION": {
                                    "OTHER": {
                                      "GOVERNMENT_MONITORING_DETAIL_EXTENSION": {
                                        "ApplicationTakenMethodType": "FaceToFace",
                                        "HMDAGenderType": "Male"
                                      }
                                    }
                                  }
                                },
                                "HMDA_RACES": {
                                  "HMDA_RACE": {
                                    "HMDA_RACE_DETAIL": {
                                      "HMDARaceType": "BlackOrAfricanAmerican"
                                    }
                                  }
                                },
                                "EXTENSION": {
                                  "OTHER": {
                                    "GOVERNMENT_MONITORING_EXTENSION": {
                                      "HMDA_ETHNICITIES": {
                                        "HMDA_ETHNICITY": {
                                          "HMDAEthnicityType": "HispanicOrLatino"
                                        }
                                      }
                                    }
                                  }
                                }
                              },
                              "RESIDENCES": {
                                "RESIDENCE": {
                                  "ADDRESS": {
                                    "AddressLineText": "10655 Birch St",
                                    "CityName": "Burbank",
                                    "PostalCode": 915021234,
                                    "StateCode": "CA"
                                  },
                                  "LANDLORD": {
                                    "LANDLORD_DETAIL": {
                                      "MonthlyRentAmount": 3500
                                    }
                                  },
                                  "RESIDENCE_DETAIL": {
                                    "BorrowerResidencyBasisType": "Rent",
                                    "BorrowerResidencyDurationMonthsCount": 43,
                                    "BorrowerResidencyType": "Current"
                                  }
                                }
                              }
                            },
                            "ROLE_DETAIL": {
                              "PartyRoleType": "Borrower"
                            }
                          }
                        ]
                      },
                      "TAXPAYER_IDENTIFIERS": {
                        "TAXPAYER_IDENTIFIER": {
                          "TaxpayerIdentifierType": "SocialSecurityNumber",
                          "TaxpayerIdentifierValue": 500507000
                        }
                      }
                    },
                    {
                      "INDIVIDUAL": {
                        "NAME": {
                          "FullName": "Kenneth Customer"
                        }
                      },
                      "ROLES": {
                        "ROLE": [
                          {
                            "PROPERTY_OWNER": {
                              "PropertyOwnerStatusType": "Proposed",
                              "RelationshipVestingType": "Individual"
                            },
                            "ROLE_DETAIL": {
                              "PartyRoleType": "PropertyOwner"
                            }
                          }
                        ]
                      }
                    },
                    {
                      "LEGAL_ENTITY": {
                        "LEGAL_ENTITY_DETAIL": {
                          "FullName": "ABC Mortgage"
                        }
                      },
                      "ADDRESSES": {
                        "ADDRESS": {
                          "AddressLineText": "412 H St, NW",
                          "CityName": "Washington",
                          "PostalCode": 200121234,
                          "StateCode": "DC"
                        }
                      },
                      "ROLES": {
                        "ROLE": [
                          {
                            "LICENSES": {
                              "LICENSE": [
                                {
                                  "LICENSE_DETAIL": {
                                    "LicenseIdentifier": "123456789111"
                                  }
                                }
                              ]
                            },
                            "ROLE_DETAIL": {
                              "PartyRoleType": "LoanOriginationCompany"
                            }
                          }
                        ]
                      }
                    },
                    {
                      "INDIVIDUAL": {
                        "CONTACT_POINTS": {
                          "CONTACT_POINT": {
                            "CONTACT_POINT_TELEPHONE": {
                              "ContactPointTelephoneValue": 2023333333
                            }
                          }
                        },
                        "NAME": {
                          "FirstName": "John",
                          "LastName": "Done"
                        }
                      },
                      "ROLES": {
                        "ROLE": [
                          {
                            "LICENSES": {
                              "LICENSE": [
                                {
                                  "LICENSE_DETAIL": {
                                    "LicenseIdentifier": 123456789012
                                  }
                                }
                              ]
                            },
                            "ROLE_DETAIL": {
                              "PartyRoleType": "LoanOriginator"
                            }
                          }
                        ]
                      }
                    }
                  ]
                },
                "RELATIONSHIPS": {
                  "RELATIONSHIP": ["", "", "", "", "", "", "", "", ""]
                }
              }
            ]
          }
        }
      ]
    }
  }
}
baharalidurrani commented 1 year ago

I used https://github.com/michaelkourlas/node-js2xmlparser to achieve the desired results.

davidcalhoun commented 1 year ago

It's not clear to me what the input, output, and desired output are here and the example is too large. I'm closing this out, but feel free to reopen or open a new issue with a clear minimal test case, with clear input and output and expected output.