Modernization: _'0x0D' is invalid within a JSON string. The string should be correctly escaped.

%3CLINGO-SUB%20id%3D%22lingo-sub-3329697%22%20slang%3D%22en-US%22%3EModernization%3A%20_'0x0D'%20is%20invalid%20within%20a%20JSON%20string.%20The%20string%20should%20be%20correctly%20escaped.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3329697%22%20slang%3D%22en-US%22%3E%3CH4%20id%3D%22toc-hId-1118985071%22%20id%3D%22toc-hId-1118985749%22%3EProblem%20Area%3C%2FH4%3E%3CP%3EPage%20Transformation%3A%20Error%20during%20the%20use%20of%20page%20transformation%20from%20PnP%20PowerShell%3C%2FP%3E%3CH4%20id%3D%22toc-hId--688469392%22%20id%3D%22toc-hId--688468714%22%3EExpected%20or%20Desired%20Behavior%3C%2FH4%3E%3CP%3EConvertTo-PnPPage%20PnP%20PowerShell%20command%20should%20modernize%20the%20web%20part%20pages%20having%20script%20editor%20web%20parts.%20It%20should%20convert%20classic%20OOB%20script%20editor%20web%20parts%20to%20configured%20react%20script%20editor%20web%20part.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EPnP%20PowerShell%20Online%20Version%20Details%3A%3C%2FSTRONG%3E%3CBR%20%2F%3EName%3A%20SharePointPnPPowerShellOnline%3CBR%20%2F%3EVersion%3A%203.29.2101.0%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CH4%20id%3D%22toc-hId-1799043441%22%20id%3D%22toc-hId-1799044119%22%3EObserved%20Behavior%3C%2FH4%3E%3CP%3EGetting%20the%20below%20error%20while%20trying%20to%20modernize%20the%20page%20with%20script%20editor%20web%20part%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23DF0000%22%3E%3CEM%3E'0x0D'%20is%20invalid%20within%20a%20JSON%20string.%20The%20string%20should%20be%20correctly%20escaped.%20Path%3A%20%24%20%7C%20LineNumber%3A%200%20%7C%20BytePositionInLine%3A%20317.%20at%20System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack%26amp%3B%20readStack%2C%20JsonReaderException%20ex)%3CBR%20%2F%3Eat%20System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions%20options%2C%20Utf8JsonReader%26amp%3B%20reader%2C%20ReadStack%26amp%3B%20readStack)%3CBR%20%2F%3Eat%20System.Text.Json.JsonSerializer.ReadCore(Type%20returnType%2C%20JsonSerializerOptions%20options%2C%20Utf8JsonReader%26amp%3B%20reader)%3CBR%20%2F%3Eat%20System.Text.Json.JsonSerializer.Deserialize(String%20json%2C%20Type%20returnType%2C%20JsonSerializerOptions%20options)%3CBR%20%2F%3Eat%20System.Text.Json.JsonSerializer.Deserialize%5BTValue%5D(String%20json%2C%20JsonSerializerOptions%20options)%3CBR%20%2F%3Eat%20PnP.Core.Model.SharePoint.PageWebPart.set_PropertiesJson(String%20value)%3CBR%20%2F%3Eat%20PnP.Framework.Modernization.Transform.ContentTransformator.Transform(List%601%20webParts)%3CBR%20%2F%3Eat%20PnP.Framework.Modernization.Transform.PageTransformator.Transform(PageTransformationInformation%20pageTransformationInformation)%3C%2FEM%3E%3C%2FFONT%3E%3C%2FP%3E%3CH3%20id%3D%22toc-hId-1788540337%22%20id%3D%22toc-hId-1788541015%22%3EPage%20Transformation%20Settings%3C%2FH3%3E%3CP%3EProperty%20Setting%3C%2FP%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3EEngine%20version%3C%2FTD%3E%3CTD%3E1.9.1.0%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ETarget%20Page%20Takes%20Source%20Page%20Name%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ETarget%20Page%20Prefix%3C%2FTD%3E%3CTD%3EMigrated_%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESource%20Page%20Prefix%3C%2FTD%3E%3CTD%3EPrevious_%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECopy%20Page%20Metadata%3C%2FTD%3E%3CTD%3ETrue%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESet%20Author%20In%20Page%20Header%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EReplace%20Home%20Page%20With%20Default%20Home%20Page%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EOverwrite%3C%2FTD%3E%3CTD%3ETrue%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ETarget%20Page%20Name%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ETarget%20Page%20Folder%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ETarget%20Page%20Folder%20Overrides%20Default%20Folder%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EKeep%20Page%20Specific%20Permissions%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ERemove%20Empty%20Sections%20And%20Columns%3C%2FTD%3E%3CTD%3ETrue%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EHandle%20Wiki%20Images%20And%20Videos%3C%2FTD%3E%3CTD%3ETrue%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EAdd%20Table%20List%20Image%20As%20Image%20Web%20Part%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EKeep%20Page%20Creation%20Modification%20Information%3C%2FTD%3E%3CTD%3ETrue%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EPublish%20Created%20Page%3C%2FTD%3E%3CTD%3ETrue%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EPost%20As%20News%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EDisable%20Page%20Comments%3C%2FTD%3E%3CTD%3ETrue%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESkip%20Url%20Rewrite%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESkip%20Default%20Url%20Rewrite%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EUrl%20Mapping%20File%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESkip%20Hidden%20Web%20Parts%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ETerm%20Mapping%20File%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESkip%20Term%20Store%20Mapping%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESkip%20User%20Mapping%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EUser%20Mapping%20File%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EL%20D%20A%20P%20Connection%20String%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESkip%20Telemetry%3C%2FTD%3E%3CTD%3EFalse%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CH3%20id%3D%22toc-hId--18914126%22%20id%3D%22toc-hId--18913448%22%3ETransformation%20Operation%20Details%3C%2FH3%3E%3CP%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EIt%20is%20similar%20to%20issue%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fmodernization%2Fissues%2Furl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fpnp%2Fmodernization%2Fissues%2F606%3C%2FA%3E%3C%2FP%3E%3CP%3EIt%20is%20working%20fine%20if%20I%20remove%20the%20newline%20character%20from%20the%20script.%20But%20for%20us%20it%20is%20a%20lot%20of%20pages%20and%20will%20not%20be%20feasible%20to%20manually%20remove%20the%20newline%20character%20from%20each%20script.%20Is%20there%20any%20alternative%20solution%20to%20fix%20this%20issues%20for%20all%20of%20the%20pages.%3C%2FP%3E%3CH4%20id%3D%22toc-hId-671647348%22%20id%3D%22toc-hId-671648026%22%3ESteps%20to%20Reproduce%3C%2FH4%3E%3CP%3EInstall%20the%20react-script%20editor%20web%20part%20to%20the%20app%20catalog%20from%20the%20link%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fmodernization%2Fissues%2Furl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fpnp%2Fsp-dev-fx-webparts%2Ftree%2Fmain%2Fsamples%2Freact-script-editor%3C%2FA%3E%3CBR%20%2F%3ECreate%20a%20web%20part%20page%20in%20a%20classic%20SharePoint%20site%2C%20add%20OOB%20script%20editor%20web%20part%20and%20add%20the%20below%20sample%20script%20in%20the%20code%20snippet%20of%20the%20script%20editor%20web%20part.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CU%3E%3CSTRONG%3ESample%20Script%3A%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%3CH1%20id%3D%22toc-hId--39919656%22%3EMy%20First%20JavaScript%3C%2FH1%3E%0A%3CBUTTON%20type%3D%22button%22%20onclick%3D%22document.getElementById('demo').innerHTML%20%3D%20Date()%22%3EClick%20me%20to%20display%20Date%20and%20Time.%3C%2FBUTTON%3E%0A%3CP%20id%3D%22demo%22%3E%20%3C%2FP%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20use%20the%20below%20script%20to%20modernize%20the%20page%20with%20the%20switch%20-UseCommunityScriptEditor%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EConvertTo-PnPPage%20-Identity%20%24page.FieldValues%5B%22ID%22%5D%20-Overwrite%0A-DisablePageComments%20-AddTableListImageAsImageWebPart%3A%20%24false%0A-ClearCache%20-SkipItemLevelPermissionCopyToClientSidePage%0A-TakeSourcePageName%3A%24TakeSourcePageName%20-LogType%20File%0A-LogFolder%20%24LogOutputFolder%20-LogVerbose%0A-LogSkipFlush%20-KeepPageCreationModificationInformation%0A-UseCommunityScriptEditor%20-CopyPageMetadata%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3329697%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EModernization%20Tooling%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%20Modern%20Search%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Escript%20editor%20webpart%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%20Modern%20Pages%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

Problem Area

Page Transformation: Error during the use of page transformation from PnP PowerShell

Expected or Desired Behavior

ConvertTo-PnPPage PnP PowerShell command should modernize the web part pages having script editor web parts. It should convert classic OOB script editor web parts to configured react script editor web part.

 

PnP PowerShell Online Version Details:
Name: SharePointPnPPowerShellOnline
Version: 3.29.2101.0

 

Observed Behavior

Getting the below error while trying to modernize the page with script editor web part:

 

'0x0D' is invalid within a JSON string. The string should be correctly escaped. Path: $ | LineNumber: 0 | BytePositionInLine: 317. at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, JsonReaderException ex)
at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at PnP.Core.Model.SharePoint.PageWebPart.set_PropertiesJson(String value)
at PnP.Framework.Modernization.Transform.ContentTransformator.Transform(List`1 webParts)
at PnP.Framework.Modernization.Transform.PageTransformator.Transform(PageTransformationInformation pageTransformationInformation)

Page Transformation Settings

Property Setting

Engine version1.9.1.0
Target Page Takes Source Page NameFalse
Target Page PrefixMigrated_
Source Page PrefixPrevious_
Copy Page MetadataTrue
Set Author In Page HeaderFalse
Replace Home Page With Default Home PageFalse
OverwriteTrue
Target Page Name 
Target Page Folder 
Target Page Folder Overrides Default FolderFalse
Keep Page Specific PermissionsFalse
Remove Empty Sections And ColumnsTrue
Handle Wiki Images And VideosTrue
Add Table List Image As Image Web PartFalse
Keep Page Creation Modification InformationTrue
Publish Created PageTrue
Post As NewsFalse
Disable Page CommentsTrue
Skip Url RewriteFalse
Skip Default Url RewriteFalse
Url Mapping File 
Skip Hidden Web PartsFalse
Term Mapping File 
Skip Term Store MappingFalse
Skip User MappingFalse
User Mapping File 
L D A P Connection String 
Skip TelemetryFalse

Transformation Operation Details

Note: It is similar to issue https://github.com/pnp/modernization/issues/606

It is working fine if I remove the newline character from the script. But for us it is a lot of pages and will not be feasible to manually remove the newline character from each script. Is there any alternative solution to fix this issues for all of the pages.

Steps to Reproduce

Install the react-script editor web part to the app catalog from the link https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-script-editor
Create a web part page in a classic SharePoint site, add OOB script editor web part and add the below sample script in the code snippet of the script editor web part.

 

Sample Script:

<h1>My First JavaScript</h1>
<button type="button"onclick="document.getElementById('demo').innerHTML = Date()">Click me to display Date and Time.</button>
<p id="demo"> </p>

 

Then use the below script to modernize the page with the switch -UseCommunityScriptEditor:

 

ConvertTo-PnPPage -Identity $page.FieldValues["ID"] -Overwrite
-DisablePageComments -AddTableListImageAsImageWebPart: $false
-ClearCache -SkipItemLevelPermissionCopyToClientSidePage
-TakeSourcePageName:$TakeSourcePageName -LogType File
-LogFolder $LogOutputFolder -LogVerbose
-LogSkipFlush -KeepPageCreationModificationInformation
-UseCommunityScriptEditor -CopyPageMetadata

 

 

0 Replies