powershell
powershell copied to clipboard
[BUG] Get-PnPPage often fails with what looks like a JSON error
Reporting an Issue or Missing Feature
When using Get-PnPPage to fetch a SharePoint page, it often fails.
It doesn't fail every time, but it seems to fail more often than not in my situation. It seems to be consistent on the pages in question: it either works or doesn't for a given page.
Things of note: -- The pages involved have all been published -- Sometimes, but not always, the page name (though not the FileLeafRef) contains special characters (such as "&")
Note: this same behavior was reported two years ago, and for some reason converted from an issue to a discussion. But the discussion was never resolved, and it remains unfixed.
https://github.com/pnp/powershell/issues/1440 https://github.com/pnp/powershell/discussions/1442
Expected behavior
When using FileLeafRef to supply the -Identity parameter for Get-PnPPage, I expect a page object returned.
Actual behavior
In actuality, it often but not always errors out with what seems to be a "bad JSON" kind of error.
Error:
Get-PnPPage: 's' is invalid after a value. Expected either ',', '}', or ']'. Path: $ | LineNumber: 0 | BytePositionInLine: 13171.
Example of underlying data:
Page title: "AD&D insurance, Local 12" FileLeafRef: "Benefits-ADD-insurance-GHI-Local-12.aspx"
It will also error out if I manually paste in the file name.
Steps to reproduce behavior
Code:
$listName = "Site Pages"
$pages = Get-PnPListItem -List $listName
foreach ($page in $pages) {
$pageDetails = Get-PnPPage -Identity $page.FieldValues.FileLeafRef
}
What is the version of the Cmdlet module you are running?
2.2.0
Which operating system/environment are you running PnP PowerShell on?
- [x ] Windows
- [ ] Linux
- [ ] MacOS
- [ ] Azure Cloud Shell
- [ ] Azure Functions
- [ ] Other : please specify
Same issue different page
Page Title: Test-TEXT-Webpart /SitePages/Test-TEXT-Webpart.aspx
$page = Get-PnPPage -Identity "Test-TEXT-Webpart.aspx" Get-PnPPage: 'u' is invalid after a value. Expected either ',', '}', or ']'. Path: $ | LineNumber: 0 | BytePositionInLine: 986.
PnP.PowerShell 2.2.57
@raytri / @tom-daly - Can you try encoding the identity parameter value before the get-pnppage cmdlet and check ?
@gautamdsheth encode which way? the '-' character is url encode / html encode is '-'
Closing as no response. Let us know if this needs to be reopen.
Why was this closed? The issue has not been resolved, and Tom Daly responded immediately to Gautamdsheth's suggestion. To repeat Tom's question: How should we encode the identity parameter?
FWIW, I tried this and got the same result as without encoding: Some pages worked, some didn't. Which isn't too surprising, because isn't FileLeafRef already URL friendly?
$encodedPage = [system.uri]::EscapeDataString($page.FieldValues.FileLeafRef);
$pageDetails = Get-PnPPage -Identity $encodedPage
We have the same error (PnP.PowerShell 2.9.0):
Get-PnPPage: '' is invalid after a value. Expected either ',', '}', or ']'. Path: $ | LineNumber: 0 | BytePositionInLine: 679.
The page only contains text web parts, placeholders and images.
Please re-open this issue, as requested 10 months ago!
Is there any reliable way to reproduce this issue ? Works fine at my end , tried different combination of webparts. If we can't repro, we can't fix it. If it is random, maybe the issue is with that particular page itself ?
Closing again as no response and we can't repro.
Hello, I'm facing the same issue when collecting a template. This gives me an error in PnP.Core when a web part contains properties with JSON values not escaped correctly.
That's why it is not simple to reproduce.
{
"id": "guid",
"instanceId": "guid",
"title": "text",
"description": "text",
"audiences": [],
"serverProcessedContent": {
"htmlStrings": {},
"searchablePlainTexts": {},
"imageSources": {},
"links": {}
},
"dataVersion": "1.0",
"properties": {
"TemplateHtml": " some html code escaped with a property data-config-json=\"{"groupid": "{sitecollectionconnectedoffice365groupid}" }\""
}
The issue is that the data-config-json value is not escaped and gives the error
I found this today https://github.com/pnp/pnpcore/pull/1658 I tried and it works in some parts but does not fix my issue.
I also submitted a new pull request https://github.com/pnp/pnpcore/pull/1674 for my issue