Created
June 10, 2023 00:34
-
-
Save trackd/de3bb0b64e68ecfe2696faff34cab4e2 to your computer and use it in GitHub Desktop.
Example for /r/Powershell user, json issues + ps 5.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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