Console
Console copied to clipboard
Web API - line breaks in JSON output
Expected Behavior
My Web API response returns a well-formatted JSON response

Actual Behavior
For some reason, if a "single line" in response exceed 200 characters, a line break appears which breaks my JSON

Steps to Reproduce the Problem
- Create Web API integration point and add example file
- Set following content
[System.Web.HttpContext]::Current.Response.ContentType = "application/json";
$responseObject = @{
"PROPERTY" = (0..186 | % {"."}) -join ""
}
[Newtonsoft.Json.JsonConvert]::SerializeObject($responseObject)
Comments:
if you change 186 to 185 you will see well formated string in the output (without line breaks)
Environment:
- Sitecore PowerShell Extensions-4.7.2 for Sitecore 8.zip
- Sitecore.NET 9.0.1 (rev. 171219)
-
[x] Tested issue with clean install of Sitecore and the latest available version of SPE.
-
[ ] Asked questions on the Sitecore Slack Chat channel.
-
[ ] Reviewed questions and answers on the Sitecore Stack Exchange.
@alan-null does the same issue happen if you use ConvertTo-Json instead of Newtonsoft?
@michaellwest yup, the same.
Put this at the beginning of your script:
Set-HostProperty -HostWidth 2000
@AdamNaj It helps but I am not sure if this is a workaround or setting that everyone should set manually. Feel free to change the status of the issue if you want.
@AdamNaj Is there a way to avoid formatting when using web api?