Console icon indicating copy to clipboard operation
Console copied to clipboard

Web API - line breaks in JSON output

Open alan-null opened this issue 7 years ago • 6 comments

Expected Behavior

My Web API response returns a well-formatted JSON response image

Actual Behavior

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

Steps to Reproduce the Problem

  1. Create Web API integration point and add example file
  2. 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 avatar Apr 24 '18 09:04 alan-null

@alan-null does the same issue happen if you use ConvertTo-Json instead of Newtonsoft?

michaellwest avatar Apr 24 '18 14:04 michaellwest

@michaellwest yup, the same.

alan-null avatar Apr 24 '18 19:04 alan-null

Put this at the beginning of your script:

Set-HostProperty -HostWidth 2000

AdamNaj avatar Apr 26 '18 09:04 AdamNaj

@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.

alan-null avatar Apr 27 '18 09:04 alan-null

@AdamNaj Is there a way to avoid formatting when using web api?

michaellwest avatar May 06 '18 18:05 michaellwest