powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Get-PnPPage often fails with what looks like a JSON error

Open raytri opened this issue 2 years ago • 7 comments

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

raytri avatar Aug 14 '23 18:08 raytri

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

tom-daly avatar Sep 08 '23 17:09 tom-daly

@raytri / @tom-daly - Can you try encoding the identity parameter value before the get-pnppage cmdlet and check ?

gautamdsheth avatar Sep 13 '23 16:09 gautamdsheth

@gautamdsheth encode which way? the '-' character is url encode / html encode is '-'

tom-daly avatar Sep 14 '23 00:09 tom-daly

Closing as no response. Let us know if this needs to be reopen.

veronicageek avatar Oct 10 '23 17:10 veronicageek

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

raytri avatar Oct 17 '23 14:10 raytri

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.

Karstaedtd avatar Aug 20 '24 10:08 Karstaedtd

Please re-open this issue, as requested 10 months ago!

raytri avatar Aug 20 '24 14:08 raytri

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 ?

gautamdsheth avatar Sep 28 '24 18:09 gautamdsheth

Closing again as no response and we can't repro.

veronicageek avatar Oct 11 '24 19:10 veronicageek

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.

PedroMordeP avatar Jul 09 '25 11:07 PedroMordeP

I also submitted a new pull request https://github.com/pnp/pnpcore/pull/1674 for my issue

PedroMordeP avatar Jul 11 '25 11:07 PedroMordeP