Author Posts

December 15, 2016 at 5:08 pm

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?

December 18, 2016 at 1:19 pm

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.

I hope that helps.