convertfrom-json is truncating json info while parsing it

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 3 months ago.

  • Author
    Posts
  • #60244
    Profile photo of vamsee
    vamsee
    Participant

    Input json file (src.json) is shown below
    The below json file has 3 columns viz. time, type, message. And it has 2 rows of such information. The 2nd line has long message

    [
    {"time": "2016-12-14T08:56:47.622-8:00", "type": "verbose", "message": "hello world"},
    {"time": "2016-12-14T09:03:20.040-8:00", "type": "verbose", "message": "sadlhasdlhsadlhasdlhasldhasldhlashdlashd sdlasldlashdlashdlashdlhaslkhaslkdhlashdlashdlkashdlkashdlashdlkasldhaslkdhad134324324324324234234234234324234kllklnlllnnlnlnlkjn2343242342349999999999999lnlnlknlknlknlknlkxxxxxxxxxxxxxxxxxxxxxxx12345"}
    ]

    I use the below powershell code to parse the above json file content and output it to a text file
    $content=Get-Content "d:\src.json" -Raw
    ConvertFrom-Json $content | out-file "D:\dest.txt"

    The output file "dest.txt" is shown below
    time type message
    —- —- ——-
    2016-12-14T08:56:47.622-8:00 verbose hello world
    2016-12-14T09:03:20.040-8:00 verbose sadlhasdlhsadlhasdlhasldhasldhlashdlashd sdlasldlashdlashdlashdlhaslkhaslkdhlashdlashdlkashdlkashdlashdlkasldhaslkdhad134324324324324234234234234324234kllklnlllnnlnlnlkjn234324234234999999...

    As you can see the 2nd row's message portion is truncated. You can "..." at the end of the message.

    Can I know why convertfrom-json truncates it?

  • #60409
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    According to the documentation (Notes section) on MSDN of the Out-File cmdlet sends unformatted object to a formatting cmdlet. Which is Format-Table in your case before writting the file to disk.

    https://msdn.microsoft.com/en-us/powershell/reference/5.0/microsoft.powershell.utility/out-file

    I hope that helps.

You must be logged in to reply to this topic.