Hello all,
I am trying to convert a json file to csv using Powershell. I created the script but it throws an error "Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'."
The json is in the below format
{
"STARTEND" : "S",
"ITEMS" :
[
{
"ItemID" : "00501016204234",
"Locked" : "N",
"Quantity" : 12,
"Delimiters" :
[
{
"PurchaseOrderID" : "00000000000000000001",
"Quantity" : "12",
"COOM" : "IN",
"COOP" : "IN",
"COOF" : "IN"
}
]
},
{
"ItemID" : "00501016503229",
"Locked" : "N",
"Quantity" : 5,
"Delimiters" :
[
{
"PurchaseOrderID" : "00000000000000000001",
"Quantity" : "5",
"COOM" : "IN",
"COOP" : "IN",
"COOF" : "IN"
}
]
}
]
}
My script is as below
$pathToJsonFile = "E:\DataLoad\inventory_replica.json"
$pathToOutputFile = "E:\DataLoad\inventory_replica.csv"
((Get-Content -Path $pathToJsonFile) | ConvertFrom-Json) | ForEach-Object {
$STARTEND = $_.Name
$ITEMS = $_.ITEMS | ForEach-Object {
$ItemID = $_.ItemID
$Locked = $_.Locked
$Quantity = $_.Quantity
$Delimiters += $_.Delimiters | ForEach-Object {
[pscustomobject] @{
'STARTEND' = $STARTEND
'ITEMS' = $ITEMS
'ItemID' = $ItemID
'Locked' = $Locked
'PurchaseOrderID' = $_.PurchaseOrderID
'Quantity' = $_.Quantity
'COOM' = $_.COOM
'COOP' = $_.COOP
'COOF' = $_.COOF
}
}
}
}
$Delimiters | Export-CSV $pathToOutputFile -NoTypeInformation
Thanks,
Seth
I am trying to convert a json file to csv using Powershell. I created the script but it throws an error "Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'."
The json is in the below format
{
"STARTEND" : "S",
"ITEMS" :
[
{
"ItemID" : "00501016204234",
"Locked" : "N",
"Quantity" : 12,
"Delimiters" :
[
{
"PurchaseOrderID" : "00000000000000000001",
"Quantity" : "12",
"COOM" : "IN",
"COOP" : "IN",
"COOF" : "IN"
}
]
},
{
"ItemID" : "00501016503229",
"Locked" : "N",
"Quantity" : 5,
"Delimiters" :
[
{
"PurchaseOrderID" : "00000000000000000001",
"Quantity" : "5",
"COOM" : "IN",
"COOP" : "IN",
"COOF" : "IN"
}
]
}
]
}
My script is as below
$pathToJsonFile = "E:\DataLoad\inventory_replica.json"
$pathToOutputFile = "E:\DataLoad\inventory_replica.csv"
((Get-Content -Path $pathToJsonFile) | ConvertFrom-Json) | ForEach-Object {
$STARTEND = $_.Name
$ITEMS = $_.ITEMS | ForEach-Object {
$ItemID = $_.ItemID
$Locked = $_.Locked
$Quantity = $_.Quantity
$Delimiters += $_.Delimiters | ForEach-Object {
[pscustomobject] @{
'STARTEND' = $STARTEND
'ITEMS' = $ITEMS
'ItemID' = $ItemID
'Locked' = $Locked
'PurchaseOrderID' = $_.PurchaseOrderID
'Quantity' = $_.Quantity
'COOM' = $_.COOM
'COOP' = $_.COOP
'COOF' = $_.COOF
}
}
}
}
$Delimiters | Export-CSV $pathToOutputFile -NoTypeInformation
Thanks,
Seth