# Why does my generated JSON have too many "\\\\"?

**URL:** <https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809>\
**Category:** PowerShell Help\
**Created:** [August 16, 2020, 9:47pm UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809 "2020-08-16T21:47:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![martins](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@martins](https://forums.powershell.org/u/martins)\
**Post date:** [August 16, 2020, 9:47pm UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809/1 "2020-08-16T21:47:36Z")

</div>

Dear Community

I have a Powershell Script which generates a JSON file with data in it.

I have a problem with this file though. It generates double the amount of “\”!

Do you know how I could solve this?

Here is my Code to generate the JSON File:

`[ordered]@{`  
`pcname='ENTER HERE';`  
`share='\ENTER HERE\C$';`  
`filename='ENTER HERE';`  
`destfilepath='some\folder';`  
`destfile='$in.share$in.destfilepath$in.filename';`  
`RDdestfile='C:$in.destfilepath&#039;;`  
`Username="ENTER HERE";`  
`Password="ENTER HERE";`  
`EncryptedPassword=""`  
`} | ConvertTo-Json | Out-File "$secFile"`

&nbsp;

$secFile is just a path to save the file to. Just tell me if you need this too.

The output JSON file looks liek this though:

```auto
{
"pcname": "ENTER HERE",
"share": "\\\\ENTER HERE\\C$",
"filename": "ENTER HERE",
"destfilepath": "some\\folder",
"destfile": "$in.share\\$in.destfilepath\\$in.filename",
"RDdestfile": "C:\\$in.destfilepath\\",
"Username": "ENTER HERE",
"Password": "ENTER HERE",
"EncryptedPassword": ""
}

```

Greetings

Martin

&nbsp;

Edit: I also posted this question in Stackoverflow and the Microsoft Tech Community, just so you know  
[https://stackoverflow.com/questions/63446524/why-does-my-generated-json-have-too-many](https://stackoverflow.com/questions/63446524/why-does-my-generated-json-have-too-many)

[https://techcommunity.microsoft.com/t5/windows-powershell/why-does-my-generated-json-have-too-many-quot-quot/td-p/1592234](https://techcommunity.microsoft.com/t5/windows-powershell/why-does-my-generated-json-have-too-many-quot-quot/td-p/1592234)

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [August 17, 2020, 5:35am UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809/2 "2020-08-17T05:35:46Z")

</div>

It appears it needs to escape the backslashes. It imports just fine, what’s the actual issue?

```auto
[pscustomobject]@{
pcname='ENTER HERE';
share='\\ENTER HERE\C$';
filename='ENTER HERE';
destfilepath='some\folder';
#destfile='$in.share\$in.destfilepath\$in.filename';
RDdestfile='C:\$in.destfilepath\';
Username="ENTER HERE";
Password="ENTER HERE";
EncryptedPassword=""
} | Convertto-Json -OutVariable results

$results | ConvertFrom-Json

```

Output

```auto
pcname : ENTER HERE
share : \\ENTER HERE\C$
filename : ENTER HERE
destfilepath : some\folder
RDdestfile : C:\$in.destfilepath\
Username : ENTER HERE
Password : ENTER HERE
EncryptedPassword : 

```

---

<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:** [August 17, 2020, 5:52am UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809/3 "2020-08-17T05:52:23Z")

</div>

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.

[https://stackoverflow.com/questions/63446524/why-does-my-generated-json-have-too-many](https://stackoverflow.com/questions/63446524/why-does-my-generated-json-have-too-many)

Thanks

---

<div class="post-metadata">

**Author:** ![martins](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@martins](https://forums.powershell.org/u/martins)\
**Post date:** [August 17, 2020, 8:35pm UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809/4 "2020-08-17T20:35:56Z")

</div>

Im sorry for the inconvenience. I will learn from my mistake and put the link in

&nbsp;

Greetings

Martin

---

<div class="post-metadata">

**Author:** ![martins](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@martins](https://forums.powershell.org/u/martins)\
**Post date:** [August 17, 2020, 8:45pm UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809/5 "2020-08-17T20:45:03Z")

</div>

Hi

My actual problem is that when it gets put back into place it gets multiplied.

Example before:

share:\\ENTER HERE\C$

&nbsp;

Example after:

share:\\\\ENTER HERE\\C$

&nbsp;

Greetings

Martin

---

<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:** [August 18, 2020, 12:15am UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809/6 "2020-08-18T00:15:35Z")

</div>

> [@](#):
>
> My actual problem is that when it gets put back into place it gets multiplied.

I cannot reproduce your issue. When I run the following code …

```
[ordered]@{
pcname = 'ENTER HERE'
share = '\\ENTER HERE\C$'
filename = 'ENTER HERE'
destfilepath = 'some\folder'
destfile = '$in.share\$in.destfilepath\$in.filename'
RDdestfile = 'C:\$in.destfilepath\'
Username = "ENTER HERE"
Password = "ENTER HERE"
EncryptedPassword = ""
} | ConvertTo-Json | Out-File $secFile

Get-Content -Path $secFile | ConvertFrom-Json
```

I get this as the result:

```
pcname : ENTER HERE
share : \\ENTER HERE\C$
filename : ENTER HERE
destfilepath : some\folder
destfile : $in.share\$in.destfilepath\$in.filename
RDdestfile : C:\$in.destfilepath\
Username : ENTER HERE
Password : ENTER HERE
EncryptedPassword :
```

---

<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:29pm UTC](https://forums.powershell.org/t/why-does-my-generated-json-have-too-many/14809/7 "2024-05-16T20:29:04Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


