Why does my generated JSON have too many “\\”?

Welcome Forums General PowerShell Q&A Why does my generated JSON have too many “\\”?

Viewing 5 reply threads
  • Author
    Posts
    • #250028
      Participant
      Topics: 2
      Replies: 4
      Points: 31
      Rank: Member

      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\';
      Username="ENTER HERE";
      Password="ENTER HERE";
      EncryptedPassword=""
      } | ConvertTo-Json | Out-File "$secFile"

       

      $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:

      [/crayon]

      Greetings

      Martin

       

      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://techcommunity.microsoft.com/t5/windows-powershell/why-does-my-generated-json-have-too-many-quot-quot/td-p/1592234

      • This topic was modified 1 month, 1 week ago by MartinS28. Reason: Added output file
      • This topic was modified 1 month, 1 week ago by MartinS28.
      • This topic was modified 1 month, 1 week ago by MartinS28.
    • #250169
      Participant
      Topics: 8
      Replies: 568
      Points: 2,171
      Helping Hand
      Rank: Community Hero

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

      [/crayon]

      Output

      [/crayon]
    • #250175
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      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

      Thanks

    • #250523
      Participant
      Topics: 2
      Replies: 4
      Points: 31
      Rank: Member

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

       

      Greetings

      Martin

    • #250529
      Participant
      Topics: 2
      Replies: 4
      Points: 31
      Rank: Member

      Hi

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

      Example before:

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

       

      Example after:

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

       

      Greetings

      Martin

    • #250565
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      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 …

      I get this as the result:

Viewing 5 reply threads
  • You must be logged in to reply to this topic.