# Powershell convertto-json value wrap issue

**URL:** <https://forums.powershell.org/t/powershell-convertto-json-value-wrap-issue/19901>\
**Category:** PowerShell Help\
**Created:** [July 15, 2022, 7:44am UTC](https://forums.powershell.org/t/powershell-convertto-json-value-wrap-issue/19901 "2022-07-15T07:44:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forums.powershell.org/u/Ben)\
**Post date:** [July 15, 2022, 7:44am UTC](https://forums.powershell.org/t/powershell-convertto-json-value-wrap-issue/19901/1 "2022-07-15T07:44:04Z")

</div>

We used this script to crawl the system logs and convert them to json, which was successful  
However, we found that json is not able to appear characters such as line returns.  
So, is there any way to prevent line feeds or carriage returns on the message field on the powershell, or to combine line breaks or carriage returns into one line  
We tried using place to replace the n character with a space  
We’ve also tried the -join approach  
None of them are ideal

```auto
$event_system = foreach ($event_system in Get-WinEvent -LogName system) { 
                $props = @{
                    'ID' = $event_system.ID;
                    'Level' = switch ($event_system.Level){0{"LogAlways"}1{"Critical"}2{"Error"}3{"Warning"}4{"Informational"}5{"Verbose"}};
                    'ProviderName' = $event_system.ProviderName;
                    'UserId' = if($event_system.UserId -ne $null){((New-Object System.Security.Principal.SecurityIdentifier($event_system.UserId)).Translate( [System.Security.Principal.NTAccount])).Value}else{" "};
                    'Message' = $event_system.Message -replace("\r\n"," ");
                    'hostname' = [Environment]::MachineName
                }
                New-Object -TypeName PSObject -Property $props
            }
            $event_system | Select-Object hostname, ID, Level, UserId, ProviderName, Message | ConvertTo-Json

```

 ![图片](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/7/74cb98c2248e0963fbd23be89741f06c95caa287.jpeg)

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 15, 2022, 7:57am UTC](https://forums.powershell.org/t/powershell-convertto-json-value-wrap-issue/19901/2 "2022-07-15T07:57:27Z")

</div>

> [@Ben](#):
>
> So, is there any way to prevent line feeds or carriage returns on the message field on the powershell, or to combine line breaks or carriage returns into one line  
> We tried using place to replace the n character with a space  
> We’ve also tried the -join approach  
> None of them are ideal

It depends pretty much on the source of the data. In Windows usually a line break is two characters - the CR and LF. I’d try to figure out how to turn the line breaks into space characters.

You may try

```auto
$event_system.Message -replace "`r`n", ' '

```

or just …

```auto
$event_system.Message -replace "`n", ' '

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:17pm UTC](https://forums.powershell.org/t/powershell-convertto-json-value-wrap-issue/19901/3 "2024-05-16T20:17:43Z")

</div>


