View Single Post
Old 10-29-2020, 01:43 AM
Robert Hadfield's Avatar
Robert Hadfield Robert Hadfield is offline
Join Date: Oct 2020
Posts: 2
Default Powershell 7 JSON handling

Trying to update a product using powershell 7

I can get the product and convert it from JSON into an object in PS that I can work with:

$myproduct = ConvertFrom-Json (invoke-webrequest -uri
I can update an attribute:
$ = "Test Product 1.3"
I can convert it back to JSON:
$myJSON = ConvertTo-Json $myproduct -compress
But it fails on update:
$myJSON | Invoke-WebRequest -uri -method PUT -ContentType 'application/json'
With the following message:
InvalidOperation: The regular expression pattern media":{"images":["@{ is not valid.
The conversion of the media object one way or the other is messed up.

Comparing the Original:
to the Converted:
"media":{"images":["@{id=0; isMain=True; orderBy=0; image160pxUrl=; image400pxUrl=; image800pxUrl=; image1500pxUrl=; imageOriginalUrl=}"]}
You can see how different it is.

So I am trying to work out how to get around this.