Sometimes it’s nice to be able to work with text, especially when you’re building command-line applications. I usually end up with a bunch of little text formatting helper methods, and recently I made one that could format a JSON array as a nice ASCII table.

I figured that this could be of use to other people as well, so I pulled it out, cleaned it up, added a few nifties, and made it into a NuGet package: Tababular (the code is on GitHub as usual).

First you

Install-Package Tababular -ProjectName YourProject

and then you can do this:

var objects = new[]
    new {FirstColumn = "r1", SecondColumn = "hej", ThirdColumn = "hej igen"},
    new {FirstColumn = "r2", SecondColumn = "hej", ThirdColumn = "hej igen"},

var text = tableFormatter.FormatObjects(objects);


which will give you something nice to look at:

| FirstColumn  | SecondColumn  | ThirdColumn  |
| r1           | hej           | hej igen     |
| r2           | hej           | hej igen     |

and that’s it 🙂

(although there’s a few nice details, like e.g. the ability to properly format multiple lines in cells, etc.)

About the author

Mogens administrator

Author of Rebus

Leave a Reply