JSON в комплексную структуру CSV - PullRequest
0 голосов
/ 29 апреля 2020

Я написал следующий код для преобразования JSON в CSV. Однако для тега LineItems он не генерирует правильную структуру.

Код ниже:

$src = "C:\Users\sneshah\Desktop\unzip\OutputFile\"
$outputFile = "C:\Users\sneshah\Desktop\unzip\csv\"    
$foldername = Get-ChildItem $src -Filter *
foreach($files in $foldername)
{
$newfoldername = $src + $files + "\records.txt"

$pathToOutputFile = $outputFile + $files + ".csv"
((Get-Content -Path $newfoldername) | ConvertFrom-Json) |
ConvertTo-Csv -NoTypeInformation |
Set-Content $pathToOutputFile

$removeconvertedfolder = $src + $files 

Remove-Item -Path $removeconvertedfolder -Recurse

}

Пожалуйста, извините за этот огромный пост, JSON обширный, я только что извлек одну запись и вставил ее сюда.

JSON Структура:

[{"IsNonPO":false,"ApprovedState":4,"ApprovalRecords":null,"InitialUniqueName":"INVINV499-1436","SubmitDate":"2018-03-07T15:47:53Z","HoldTillDate":null,"SupplierLocation":{"UniqueName":"AD167689670"},"CreateDate":"2018-03-07T15:41:19Z","RemitToAddress":null,"Name":"INVINV499-1436","LastModified":"2018-03-07T15:48:12Z","TotalCost":{"AmountInReportingCurrency":10.2000000000,"ApproxAmountInBaseCurrency":10.2000000000,"Amount":10.2000000000,"ConversionDate":"2018-03-07T15:46:42Z","Currency":{"UniqueName":"USD"}},"TimeCreated":"2018-03-07T15:47:53Z","TaxAmount":null,"Requester":{"UniqueName":"kokrishna","PasswordAdapter":"PasswordAdapter1"},"TaxDetails":null,"VATAmount":null,"TotalInvoicedLessTax":{"AmountInReportingCurrency":10.0000000000,"ApproxAmountInBaseCurrency":10.0000000000,"Amount":10.0000000000,"ConversionDate":"2018-03-07T15:47:18Z","Currency":{"UniqueName":"USD"}},"RemitToID":null,"InvoiceNumber":"INV499","Order":{"UniqueName":"PO499"},"LineItems":[{"Description.CommonCommodityCode":null,"TaxDetail.FormulaString":null,"TaxDetail.IsDeductible":null,"OriginalPrice":null,"InvoiceLineNumber":1,"ExpectedTax.TaxRate":null,"ExpectedTax.TaxCode":null,"NumberConfirmedAccepted":0E-10,"ChargeAmount":null,"SplitAccountings":[{"PONumber":"","ERPSplitValue":"","WBSElement":null,"Percentage":100.0000000000,"Amount":{"AmountInReportingCurrency":10.0000000000,"ApproxAmountInBaseCurrency":10.0000000000,"Amount":10.0000000000,"ConversionDate":"2018-03-07T15:45:39Z","Currency":{"UniqueName":"USD"}},"Quantity":1.0000000000,"InternalOrder":null,"NumberInCollection":1,"Type":{"UniqueName":"_Percentage"},"ProcurementUnit":null,"CostCenter":null,"POLineNumber":"","GeneralLedger":null,"Asset":null,"CompanyCode":null}],"TaxAmount":{"AmountInReportingCurrency":0.2000000000,"ApproxAmountInBaseCurrency":0.2000000000,"Amount":0.2000000000,"ConversionDate":"2018-03-07T15:48:45Z","Currency":{"UniqueName":"USD"}},"ExpectedTax.IsAccrual":null,"TaxDetail.Category":null,"VATAmount":null,"ChargeDetail.ANChargeDescription":null,"Description.IndexContractPrice":null,"ServiceDetails.RequiresServiceEntry":false,"Description.Language":"","TaxDetail.Percent":null,"TaxDetail.PerUnit":null,"ShipFrom":{"State":"CA","Phone":"","Country":{"UniqueName":"US"},"PostalCode":"94203","City":"Sacramento","Fax":"","UniqueName":"AD170035991","Lines":"Deloitte Towers","Name":"DAA LE Supplier-TEST"},"DueOn":null,"Description.SupplierURL":"","DiscountAmount":null,"ServicePeriod":{"Period":"Custom","FromDate":"2018-03-06T08:00:00Z","ToDate":"2018-03-08T07:59:59Z"},"ServiceDetails.ServiceEndDate":null,"ExpectedTax.TaxableAmount":null,"ChargeDetail.ChargeAmount":null,"ServiceDetails.ExpectedAmount":null,"Description.UnitOfMeasure":{"UniqueName":"HUR"},"Description.NonContractPrice":null,"ChargeDetail.ANChargeName":null,"Description.LineItem":{"NumberInCollection":1,"InvoiceLineNumber":1},"TaxDetail.AbatementPercent":null,"MasterAgreement":null,"Description.ContractPrice":null,"IsAdHoc":true,"NumberConfirmedAcceptedWithChanges":0E-10,"BillingAddress":{"State":"CA","Phone":"","Country":{"UniqueName":"US"},"PostalCode":"94304","City":"Palo Alto","Fax":"","UniqueName":"ZH10","Lines":"3475 Deer Creek","Name":"Hi Tech US Manufacturing Plant"},"NumberInCollection":1,"NumberShipped":0E-10,"Description.ExtAttributesBitMask":0,"CommodityCode":null,"Description.ShortName":"","Supplier":{"UniqueName":"DAA LE Supplier","Name":"DAA LE Supplier"},"Description.PriceBasisQuantityDesc":null,"ServiceDetails.MaxAmount":null,"Description.ConversionFactor":null,"DeliverTo":"Komal Krishna","Description.KitUniqueName":null,"CarrierMethod":"","TaxDetail.TaxableAmount":null,"Amount":{"AmountInReportingCurrency":10.0000000000,"ApproxAmountInBaseCurrency":10.0000000000,"Amount":10.0000000000,"ConversionDate":"2018-03-07T15:45:39Z","Currency":{"UniqueName":"USD"}},"EndDate":null,"ServiceDetails.ServiceLine":true,"GRBasedInvoice":false,"OrderLineItem":null,"Description.CustomPrice":null,"ServiceDetails.ServiceStartDate":null,"ShipTo":{"State":"CA","Phone":"","Country":{"UniqueName":"US"},"PostalCode":"94304","City":"Palo Alto","Fax":"","UniqueName":"ZH10","Lines":"3475 Deer Creek","Name":"Hi Tech US Manufacturing Plant"},"SupplierOrderInfo":{"MANumber":"","OrderNumber":"PO499","ReceiptNumber":""},"ItemMasterID":null,"ReferenceDate":"2018-03-07T10:30:43Z","Description.QueryID":"","Description.PriceBasisQuantity":null,"TaxDetail.Description":null,"BasePrice":null,"Description.SupplierPartAuxiliaryID":"","ExpectedTax.Component":null,"InspectionDate":null,"IsPriceModifiedByUser":false,"ChargeDetail.TaxAmount":null,"Description.ExtendedDescription":"","SupplierLocation":{"UniqueName":"AD167689670"},"TaxDetail.TaxLocation":null,"TaxDetail.TaxAmount":null,"StartDate":null,"TaxDetail.ExemptDetail":null,"Description.Description":"Test","IsRecurring":false,"NumberConfirmedSubstituted":0E-10,"TaxDetail.AlternateTaxAmount":null,"Description.ExpirationDate":null,"Carrier":"","Description.SupplierPartNumber":"","TaxDetail.PaymentDate":null,"Order":{"UniqueName":"PO499"},"NumberConfirmedBackOrdered":0E-10,"ChargeDetail.TaxCode":null,"Description.LeadTime":0,"ERPLineItemNumber":"","Description.PriceBasisQuantityUOM":null,"Description.ItemNumber":"","Category":1,"ChargeDetail.ChargeType":null,"NumberConfirmedRejected":0E-10,"PaymentTerms":null,"TaxCode":null,"LineType":{"UniqueName":"_NonCatalogItem"},"Description.Price":{"AmountInReportingCurrency":10.0000000000,"ApproxAmountInBaseCurrency":10.0000000000,"Amount":10.0000000000,"ConversionDate":"2018-03-07T15:45:39Z","Currency":{"UniqueName":"USD"}},"TaxDetail.TaxPointDate":null,"OrderLineNumber":0,"WithholdingTaxAmount":null,"TaxDetail.Component":null,"BoughtFromPreferredSupplier":false,"Quantity":1.0000000000,"TaxDetail.Purpose":null,"OrderInfo":null,"TaxDetail.IsTriangularTransaction":null,"ExpectedTax.TaxType":null,"MALineItem":null,"TaxDetail.TriangularTransactionLawReference":null},{"Description.CommonCommodityCode":null,"TaxDetail.FormulaString":"","TaxDetail.IsDeductible":false,"OriginalPrice":null,"InvoiceLineNumber":1,"ExpectedTax.TaxRate":0E-10,"ExpectedTax.TaxCode":null,"NumberConfirmedAccepted":0E-10,"ChargeAmount":null,"SplitAccountings":[{"PONumber":"","ERPSplitValue":"","WBSElement":null,"Percentage":100.0000000000,"Amount":{"AmountInReportingCurrency":0.2000000000,"ApproxAmountInBaseCurrency":0.2000000000,"Amount":0.2000000000,"ConversionDate":"2018-03-07T15:46:41Z","Currency":{"UniqueName":"USD"}},"Quantity":1.0000000000,"InternalOrder":null,"NumberInCollection":1,"Type":{"UniqueName":"_Percentage"},"ProcurementUnit":null,"CostCenter":null,"POLineNumber":"","GeneralLedger":null,"Asset":null,"CompanyCode":null}],"TaxAmount":null,"ExpectedTax.IsAccrual":false,"TaxDetail.Category":"sales","VATAmount":null,"ChargeDetail.ANChargeDescription":null,"Description.IndexContractPrice":null,"ServiceDetails.RequiresServiceEntry":null,"Description.Language":"en","TaxDetail.Percent":2.0000000000,"TaxDetail.PerUnit":0E-10,"ShipFrom":{"State":"CA","Phone":"","Country":{"UniqueName":"US"},"PostalCode":"94203","City":"Sacramento","Fax":"","UniqueName":"AD170035991","Lines":"Deloitte Towers","Name":"DAA LE Supplier-TEST"},"DueOn":null,"Description.SupplierURL":"","DiscountAmount":null,"ServicePeriod":null,"ServiceDetails.ServiceEndDate":null,"ExpectedTax.TaxableAmount":null,"ChargeDetail.ChargeAmount":null,"ServiceDetails.ExpectedAmount":null,"Description.UnitOfMeasure":null,"Description.NonContractPrice":null,"ChargeDetail.ANChargeName":null,"Description.LineItem":{"NumberInCollection":2,"InvoiceLineNumber":1},"TaxDetail.AbatementPercent":0E-10,"MasterAgreement":null,"Description.ContractPrice":null,"IsAdHoc":true,"NumberConfirmedAcceptedWithChanges":0E-10,"BillingAddress":{"State":"CA","Phone":"","Country":{"UniqueName":"US"},"PostalCode":"94304","City":"Palo Alto","Fax":"","UniqueName":"ZH10","Lines":"3475 Deer Creek","Name":"Hi Tech US Manufacturing Plant"},"NumberInCollection":2,"NumberShipped":0E-10,"Description.ExtAttributesBitMask":0,"CommodityCode":null,"Description.ShortName":"","Supplier":{"UniqueName":"DAA LE Supplier","Name":"DAA LE Supplier"},"Description.PriceBasisQuantityDesc":null,"ServiceDetails.MaxAmount":null,"Description.ConversionFactor":null,"DeliverTo":"Komal Krishna","Description.KitUniqueName":null,"CarrierMethod":"","TaxDetail.TaxableAmount":{"AmountInReportingCurrency":10.0000000000,"ApproxAmountInBaseCurrency":10.0000000000,"Amount":10.0000000000,"ConversionDate":"2018-03-07T15:46:41Z","Currency":{"UniqueName":"USD"}},"Amount":{"AmountInReportingCurrency":0.2000000000,"ApproxAmountInBaseCurrency":0.2000000000,"Amount":0.2000000000,"ConversionDate":"2018-03-07T15:46:41Z","Currency":{"UniqueName":"USD"}},"EndDate":null,"ServiceDetails.ServiceLine":null,"GRBasedInvoice":false,"OrderLineItem":null,"Description.CustomPrice":null,"ServiceDetails.ServiceStartDate":null,"ShipTo":{"State":"CA","Phone":"","Country":{"UniqueName":"US"},"PostalCode":"94304","City":"Palo Alto","Fax":"","UniqueName":"ZH10","Lines":"3475 Deer Creek","Name":"Hi Tech US Manufacturing Plant"},"SupplierOrderInfo":{"MANumber":"","OrderNumber":"PO499","ReceiptNumber":""},"ItemMasterID":null,"ReferenceDate":"2018-03-07T10:30:43Z","Description.QueryID":"","Description.PriceBasisQuantity":null,"TaxDetail.Description":"Tax","BasePrice":null,"Description.SupplierPartAuxiliaryID":"","ExpectedTax.Component":null,"InspectionDate":null,"IsPriceModifiedByUser":false,"ChargeDetail.TaxAmount":null,"Description.ExtendedDescription":"","SupplierLocation":{"UniqueName":"AD167689670"},"TaxDetail.TaxLocation":"","TaxDetail.TaxAmount":{"AmountInReportingCurrency":0.2000000000,"ApproxAmountInBaseCurrency":0.2000000000,"Amount":0.2000000000,"ConversionDate":"2018-03-07T15:46:41Z","Currency":{"UniqueName":"USD"}},"StartDate":null,"TaxDetail.ExemptDetail":"","Description.Description":"Tax","IsRecurring":false,"NumberConfirmedSubstituted":0E-10,"TaxDetail.AlternateTaxAmount":{"AmountInReportingCurrency":0.2000000000,"ApproxAmountInBaseCurrency":0.2000000000,"Amount":0.2000000000,"ConversionDate":"2018-03-07T15:46:41Z","Currency":{"UniqueName":"USD"}},"Description.ExpirationDate":null,"Carrier":"","Description.SupplierPartNumber":"","TaxDetail.PaymentDate":null,"Order":{"UniqueName":"PO499"},"NumberConfirmedBackOrdered":0E-10,"ChargeDetail.TaxCode":null,"Description.LeadTime":0,"ERPLineItemNumber":"","Description.PriceBasisQuantityUOM":null,"Description.ItemNumber":"","Category":1,"ChargeDetail.ChargeType":null,"NumberConfirmedRejected":0E-10,"PaymentTerms":null,"TaxCode":null,"LineType":{"UniqueName":"SalesTax"},"Description.Price":{"AmountInReportingCurrency":0.2000000000,"ApproxAmountInBaseCurrency":0.2000000000,"Amount":0.2000000000,"ConversionDate":"2018-03-07T15:46:41Z","Currency":{"UniqueName":"USD"}},"TaxDetail.TaxPointDate":null,"OrderLineNumber":0,"WithholdingTaxAmount":null,"TaxDetail.Component":null,"BoughtFromPreferredSupplier":false,"Quantity":1.0000000000,"TaxDetail.Purpose":"","OrderInfo":null,"TaxDetail.IsTriangularTransaction":false,"ExpectedTax.TaxType":{"UniqueName":"SalesTax"},"MALineItem":null,"TaxDetail.TriangularTransactionLawReference":""}],"ChangedBy":null,"ApprovedDate":"2018-03-07T15:48:10Z","InvoiceOrigin":"supplier","TotalWithholdingTax":{"AmountInReportingCurrency":0E-10,"ApproxAmountInBaseCurrency":0E-10,"Amount":0E-10,"ConversionDate":"2018-03-07T15:47:18Z","Currency":{"UniqueName":"USD"}},"Signed":false,"ScheduledPaymentDate":"2018-03-27T09:30:43Z","PreviousApprovalRequestsVersion":-1,"ResubmitDate":null,"PurchaseOrg":{"UniqueName":"ZH01"},"MaxDiscountApplicable":{"AmountInReportingCurrency":0.3000000000,"ApproxAmountInBaseCurrency":0.3000000000,"Amount":0.3000000000,"ConversionDate":"2018-03-07T15:48:45Z","Currency":{"UniqueName":"USD"}},"ServicePeriod":null,"IsTaxInLine":true,"ApprovalRequests":null,"Active":true,"InvoiceSourceDocument":"PurchaseOrder","InvoiceStatusString":"Reconciled","NextVersion":null,"TaxExchangeRate":0E-10,"HeaderLevel":false,"UniqueName":"INVINV499-1436","TotalInvoiced":{"AmountInReportingCurrency":10.2000000000,"ApproxAmountInBaseCurrency":10.2000000000,"Amount":10.2000000000,"ConversionDate":"2018-03-07T15:47:18Z","Currency":{"UniqueName":"USD"}},"Category":1,"MasterAgreement":null,"InvoiceSubmissionMethod":"Online","InvoicePurpose":"standard","PaymentTerms":{"UniqueName":"PT1"},"ReconciledDate":"2018-03-07T16:05:41Z","AccountReceivableID":"","ServiceLocation":null,"TotalTax":{"AmountInReportingCurrency":0.2000000000,"ApproxAmountInBaseCurrency":0.2000000000,"Amount":0.2000000000,"ConversionDate":"2018-03-07T15:47:18Z","Currency":{"UniqueName":"USD"}},"Supplier":{"UniqueName":"DAA LE Supplier","Name":"DAA LE Supplier"},"InvoiceDate":"2018-03-07T10:30:43Z","StatusString":"Reconciled","PreviousVersion":null,"ApprovalRequestsVersion":1,"UpperCaseInvoiceNumber":"INV499","TimeUpdated":"2019-08-22T10:20:31Z","VersionNumber":1,"Type":"ariba.invoicing.core.Invoice","InvoiceOriginType":0,"SupplierName":"","Attachments.Attachments":null,"InvoiceState":4,"SoldTo":{"Address":{"State":"NC","Phone":"","Country":{"UniqueName":"US"},"PostalCode":"28202-4200","City":"Charlotte","Fax":"","UniqueName":"AD86365369","Lines":"550 S. Tryon Street\nSuite 2500","Name":"Deloitte Consulting - TEST"},"Name":""},"CompanyCode":{"UniqueName":"ZH01"},"Preparer":{"UniqueName":"aribasystem","PasswordAdapter":"PasswordAdapter1"},"InvoiceToCredit":null}]

Ожидаемая последовательность в файле csv для lineItems будет

LineItems/0/SplitAccountings/0/WBSElement/CompanyCodeUniqueNameList,LineItems/0/SplitAccountings/0/WBSElement/Description,LineItems/0/SplitAccountings/0/WBSElement/UniqueName,LineItems/0/SplitAccountings/0/WBSElement/ProjectNumber,LineItems/0/SplitAccountings/0/Amount/AmountInReportingCurrency,LineItems/0/SplitAccountings/0/Amount/ApproxAmountInBaseCurrency,LineItems/0/SplitAccountings/0/Amount/Amount,LineItems/0/SplitAccountings/0/Amount/ConversionDate,LineItems/0/SplitAccountings/0/Amount/Currency/UniqueName,LineItems/0/SplitAccountings/0/Quantity,LineItems/0/SplitAccountings/0/InternalOrder,LineItems/0/SplitAccountings/0/NumberInCollection,LineItems/0/SplitAccountings/0/Type/UniqueName,LineItems/0/SplitAccountings/0/ProcurementUnit,LineItems/0/SplitAccountings/0/CostCenter/ProcurementUnit,LineItems/0/SplitAccountings/0/CostCenter/UniqueName,LineItems/0/SplitAccountings/0/CostCenter/CompanyCode/UniqueName,LineItems/0/SplitAccountings/0/CostCenter/CostCenterDescription,LineItems/0/SplitAccountings/0/POLineNumber,LineItems/0/SplitAccountings/0/GeneralLedger/GeneralLedgerDescription,LineItems/0/SplitAccountings/0/GeneralLedger/GeneralLedgerDescription2,LineItems/0/SplitAccountings/0/GeneralLedger/UniqueName,LineItems/0/SplitAccountings/0/GeneralLedger/CompanyCode/UniqueName,LineItems/0/SplitAccountings/0/GeneralLedger/FieldStatusGroup,LineItems/0/SplitAccountings/0/GeneralLedger/ExternalId,LineItems/0/SplitAccountings/0/Asset,LineItems/0/SplitAccountings/0/CompanyCode,LineItems/0/TaxAmount,LineItems/0/ExpectedTax.IsAccrual,LineItems/0/TaxDetail.Category,LineItems/0/VATAmount,LineItems/0/ChargeDetail.ANChargeDescription,LineItems/0/Description.IndexContractPrice,LineItems/0/ServiceDetails.RequiresServiceEntry,LineItems/0/Description.Language,LineItems/0/TaxDetail.Percent,LineItems/0/TaxDetail.PerUnit,LineItems/0/ShipFrom/State,LineItems/0/ShipFrom/Phone,LineItems/0/ShipFrom/Country/UniqueName,LineItems/0/ShipFrom/PostalCode,LineItems/0/ShipFrom/City,LineItems/0/ShipFrom/Fax,LineItems/0/ShipFrom/UniqueName,LineItems/0/ShipFrom/Lines,LineItems/0/ShipFrom/Name,LineItems/0/DueOn,LineItems/0/Description.SupplierURL,LineItems/0/DiscountAmount,LineItems/0/ServicePeriod,LineItems/0/ServiceDetails.ServiceEndDate,LineItems/0/ExpectedTax.TaxableAmount,LineItems/0/ChargeDetail.ChargeAmount,LineItems/0/ServiceDetails.ExpectedAmount,LineItems/0/Description.UnitOfMeasure/UniqueName,LineItems/0/Description.NonContractPrice,LineItems/0/ChargeDetail.ANChargeName,LineItems/0/Description.LineItem/NumberInCollection,LineItems/0/TaxDetail.AbatementPercent,LineItems/0/MasterAgreement/UniqueName,LineItems/0/Description.ContractPrice,LineItems/0/IsAdHoc,LineItems/0/NumberConfirmedAcceptedWithChanges,LineItems/0/BillingAddress/State,LineItems/0/BillingAddress/Phone,LineItems/0/BillingAddress/Country/UniqueName,LineItems/0/BillingAddress/PostalCode,LineItems/0/BillingAddress/City,LineItems/0/BillingAddress/Fax,LineItems/0/BillingAddress/UniqueName,LineItems/0/BillingAddress/Lines,LineItems/0/BillingAddress/Name,LineItems/0/NumberInCollection,LineItems/0/NumberShipped,LineItems/0/Description.ExtAttributesBitMask,LineItems/0/CommodityCode/UniqueName,LineItems/0/Description.ShortName,LineItems/0/Supplier/UniqueName,LineItems/0/Supplier/Name,LineItems/0/Description.PriceBasisQuantityDesc,LineItems/0/ServiceDetails.MaxAmount,LineItems/0/Description.ConversionFactor,LineItems/0/DeliverTo,LineItems/0/Description.KitUniqueName,LineItems/0/CarrierMethod,LineItems/0/TaxDetail.TaxableAmount,LineItems/0/Amount/AmountInReportingCurrency,LineItems/0/Amount/ApproxAmountInBaseCurrency,LineItems/0/Amount/Amount,LineItems/0/Amount/ConversionDate,LineItems/0/Amount/Currency/UniqueName,LineItems/0/EndDate,LineItems/0/ServiceDetails.ServiceLine,LineItems/0/GRBasedInvoice,LineItems/0/OrderLineItem/NumberInCollection,LineItems/0/Description.CustomPrice/AmountInReportingCurrency,LineItems/0/Description.CustomPrice/ApproxAmountInBaseCurrency,LineItems/0/Description.CustomPrice/Amount,LineItems/0/Description.CustomPrice/ConversionDate,LineItems/0/Description.CustomPrice/Currency/UniqueName,LineItems/0/ServiceDetails.ServiceStartDate,LineItems/0/ShipTo/State,LineItems/0/ShipTo/Phone,LineItems/0/ShipTo/Country/UniqueName,LineItems/0/ShipTo/PostalCode,LineItems/0/ShipTo/City,LineItems/0/ShipTo/Fax,LineItems/0/ShipTo/UniqueName,LineItems/0/ShipTo/Lines,LineItems/0/ShipTo/Name,LineItems/0/SupplierOrderInfo/MANumber,LineItems/0/SupplierOrderInfo/OrderNumber,LineItems/0/SupplierOrderInfo/ReceiptNumber,LineItems/0/ItemMasterID,LineItems/0/ReferenceDate,LineItems/0/Description.QueryID,LineItems/0/Description.PriceBasisQuantity,LineItems/0/TaxDetail.Description,LineItems/0/BasePrice/AmountInReportingCurrency,LineItems/0/BasePrice/ApproxAmountInBaseCurrency,LineItems/0/BasePrice/Amount,LineItems/0/BasePrice/ConversionDate,LineItems/0/BasePrice/Currency/UniqueName,LineItems/0/Description.SupplierPartAuxiliaryID,LineItems/0/ExpectedTax.Component,LineItems/0/InspectionDate,LineItems/0/IsPriceModifiedByUser,LineItems/0/ChargeDetail.TaxAmount,LineItems/0/Description.ExtendedDescription,LineItems/0/SupplierLocation/UniqueName,LineItems/0/TaxDetail.TaxLocation,LineItems/0/TaxDetail.TaxAmount,LineItems/0/StartDate,LineItems/0/TaxDetail.ExemptDetail,LineItems/0/Description.Description,LineItems/0/IsRecurring,LineItems/0/NumberConfirmedSubstituted,LineItems/0/TaxDetail.AlternateTaxAmount,LineItems/0/Description.ExpirationDate,LineItems/0/Carrier,LineItems/0/Description.SupplierPartNumber,LineItems/0/TaxDetail.PaymentDate,LineItems/0/Order/UniqueName,LineItems/0/NumberConfirmedBackOrdered,LineItems/0/ChargeDetail.TaxCode,LineItems/0/Description.LeadTime,LineItems/0/ERPLineItemNumber,LineItems/0/Description.PriceBasisQuantityUOM,LineItems/0/Description.ItemNumber,LineItems/0/Category,LineItems/0/ChargeDetail.ChargeType,LineItems/0/NumberConfirmedRejected,LineItems/0/PaymentTerms,LineItems/0/TaxCode,LineItems/0/LineType/UniqueName,LineItems/0/Description.Price/AmountInReportingCurrency,LineItems/0/Description.Price/ApproxAmountInBaseCurrency,LineItems/0/Description.Price/Amount,LineItems/0/Description.Price/ConversionDate,LineItems/0/Description.Price/Currency/UniqueName,LineItems/0/TaxDetail.TaxPointDate,LineItems/0/OrderLineNumber,LineItems/0/WithholdingTaxAmount,LineItems/0/TaxDetail.Component,LineItems/0/BoughtFromPreferredSupplier,LineItems/0/Quantity,LineItems/0/TaxDetail.Purpose,LineItems/0/OrderInfo,LineItems/0/TaxDetail.IsTriangularTransaction,LineItems/0/ExpectedTax.TaxType,LineItems/0/TaxDetail.TriangularTransactionLawReference,LineItems/0/MALineItem/NumberInCollection

1 Ответ

0 голосов
/ 29 апреля 2020

Если вы просто хотите что-то, что помешает появлению System.Object[] в столбце LineItems, приведенный ниже код будет работать.

Ожидаемый результат для значения в столбце LineItems содержит запятые, поэтому он нарушит форматирование в CSV-файле (если только вы не собираетесь разбивать позиции по множеству строк и дублировать другие столбцы в каждой строке, что потребовало бы совсем другого ответа).

$data = (Get-Content -Path "$PSScriptRoot\input_data.json") | ConvertFrom-Json 

$data[0].LineItems = $data[0].LineItems | ConvertTo-Json -Depth 100 
$data[0].LineItems = Out-String -InputObject $data[0].LineItems

$data | ConvertTo-Csv -NoTypeInformation | Set-Content "$PSScriptRoot\output_data.csv"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...