Skip to content

Enhancement: Remove duplicate ID properties in JSON output for spo listitem commands #2024

@garrytrinder

Description

@garrytrinder

Raised from #1762

The issue is specific to PowerShell implementation of ConvertFrom-Json rather than the CLI, see the below output from my tests.

image

ConvertFrom-Json appears to be unable to handle properties with the same name but have different casing, adding the -AsHashtable switch works around the issue in PowerShell Core, however I do know that -AsHashtable is not present in PowerShell 5 which is bundled with the Windows OS, so users will have to use the Replace workaround as you have already stated, which is less than ideal.

We should consider removing duplicate properties from our output in this case.

When ConvertFrom-Json is used to parse the JSON output from the spo listitem commands it can fail as it cannot determine that Id and ID properties are different as it does not take casing into account.

For PowerShell 5 users, the workaround is to use replace to change the Id property name before parsing

$spolItems = (o365 spo listitem list --webUrl "https://tenant-name.sharepoint.com/sites/site-name" --title "list-title" --fields "Id,Title,Modified" -o json).ToString().Replace("ID", "_ID") | ConvertFrom-Json

For PowerShell 7 users, the workaround is to use the -AsHashtable switch on ConvertFrom-Json (note that -AsHashtable is not present in PowerShell 5.

$spolItems = o365 spo listitem list --webUrl "https://tenant-name.sharepoint.com/sites/site-name" --title "list-title" --fields "Id,Title,Modified" -o json | ConvertFrom-Json -AsHashtable

This is less than ideal, so we should look to remove the extra ID property from the spo listitem list and spo listitem get commands.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions