Skip to content

Instantly share code, notes, and snippets.

@trackd
Created June 10, 2023 00:34
Show Gist options
  • Save trackd/de3bb0b64e68ecfe2696faff34cab4e2 to your computer and use it in GitHub Desktop.
Save trackd/de3bb0b64e68ecfe2696faff34cab4e2 to your computer and use it in GitHub Desktop.
Example for /r/Powershell user, json issues + ps 5.1
function Get-LACountyParcel {
<#
.EXAMPLE
Get-LACountyParcel -Parcel <id>
#>
[CmdletBinding()]
param(
$Parcel
)
try {
# regex removes any property from the json that has 'null', to resolve the duplicate 'SubPartNumber' values.
$regex = [regex]::new('\x22\w+\x22:null\,')
# if it's only SubPartNumber that is the issue could swap to below line
# $regex = [regex]::new('"SubPartNumber":null\,')
$Request = Invoke-RestMethod -Uri "https://portal.assessor.lacounty.gov/api/parceldetail?ain=$Parcel"
if ($Request -is [String]) {
# problems parsing the json, attempting to replace and convert.
$json = $Request -replace $regex | ConvertFrom-Json
return $json.Parcel
} else {
return $Request.Parcel
}
} catch {
throw $_
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment